generated from dopt-python/py311
adapted linking dialog for consulting sessions
This commit is contained in:
+75
-5
@@ -8,12 +8,12 @@ import json
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from collections.abc import Sequence
|
||||
from pprint import pprint
|
||||
from pprint import pformat, pprint
|
||||
from typing import Annotated, Any
|
||||
|
||||
import babel
|
||||
import polars as pl
|
||||
import sqlalchemy as sql
|
||||
import sqlalchemy as sa
|
||||
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator, model_validator
|
||||
from PySide6.QtCore import QDate, Qt
|
||||
|
||||
@@ -22,11 +22,81 @@ from wce_crm.backend import backend
|
||||
from wce_crm.types import EntityIds, RecordingType
|
||||
|
||||
# %%
|
||||
empty = tuple()
|
||||
# backend.page_consulting_linking_companies(None)
|
||||
# backend.page_consulting_linking_persons(3)
|
||||
|
||||
# not any(empty)
|
||||
|
||||
all(empty)
|
||||
# %%
|
||||
@dc.dataclass(slots=True, kw_only=True)
|
||||
class LinkingPerson:
|
||||
pers_id: int
|
||||
display_name: str
|
||||
un_ids: set[int]
|
||||
|
||||
|
||||
with db.ENGINE.connect() as conn:
|
||||
# if un_id None: list all persons
|
||||
# else: list just the persons associated with the company
|
||||
|
||||
stmt = (
|
||||
sa.select(
|
||||
db.t_grunderfassung_personen.c.pers_id,
|
||||
db.t_zuordnung_personen_unternehmen.c.un_id,
|
||||
db.t_grunderfassung_personen.c.Stammdaten__name,
|
||||
db.t_grunderfassung_personen.c.Stammdaten__vorname,
|
||||
db.t_grunderfassung_personen.c.Stammdaten__ort,
|
||||
)
|
||||
.outerjoin(
|
||||
db.t_zuordnung_personen_unternehmen,
|
||||
db.t_grunderfassung_personen.c.pers_id
|
||||
== db.t_zuordnung_personen_unternehmen.c.pers_id,
|
||||
)
|
||||
.order_by(db.t_grunderfassung_personen.c.Stammdaten__name)
|
||||
)
|
||||
|
||||
# if un_id is not None:
|
||||
# person_select = person_select.select_from(
|
||||
# db.t_grunderfassung_personen.join(
|
||||
# db.t_zuordnung_personen_unternehmen,
|
||||
# db.t_grunderfassung_personen.c.pers_id
|
||||
# == db.t_zuordnung_personen_unternehmen.c.pers_id,
|
||||
# )
|
||||
# ).where(db.t_zuordnung_personen_unternehmen.c.un_id == un_id)
|
||||
|
||||
ret = conn.execute(stmt)
|
||||
|
||||
persons_map: dict[str, Any] = {}
|
||||
for row in ret:
|
||||
p_id = row.pers_id
|
||||
|
||||
if p_id not in persons_map:
|
||||
first_name = row.Stammdaten__vorname
|
||||
last_name = row.Stammdaten__name
|
||||
location_city = row.Stammdaten__ort
|
||||
|
||||
display_name = f"{first_name} {last_name}"
|
||||
if location_city:
|
||||
display_name += f" (Ort: {location_city})"
|
||||
|
||||
persons_map[p_id] = {
|
||||
"pers_id": p_id,
|
||||
"display_name": display_name,
|
||||
"un_ids": set(),
|
||||
}
|
||||
|
||||
# Falls verknüpft, ID zur Menge hinzufügen
|
||||
if row.un_id is not None:
|
||||
persons_map[p_id]["un_ids"].add(row.un_id)
|
||||
|
||||
person_names = [LinkingPerson(**data) for data in persons_map.values()]
|
||||
|
||||
|
||||
# person_names = ret.mappings().all()
|
||||
# if not person_names:
|
||||
# print(f"No persons found for 'un_id': {un_id}")
|
||||
|
||||
print(f"[Page Consulting -- Linking] Retrieved person names:\n{pformat(person_names)}")
|
||||
|
||||
# %%
|
||||
dic = {
|
||||
"t1": "test1",
|
||||
|
||||
Reference in New Issue
Block a user