generated from dopt-python/py311
prepare linking of persons and companies
This commit is contained in:
@@ -6,8 +6,9 @@ from pprint import pformat
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
import polars as pl
|
||||
import sqlalchemy as sql
|
||||
import sqlalchemy as sa
|
||||
from dopt_basics.result_pattern import wrap_result
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
|
||||
from wce_crm import db
|
||||
from wce_crm.constants import TIMEZONE_CEST
|
||||
@@ -479,7 +480,7 @@ def page_consulting_to_db(
|
||||
"[Consulting Page] Call update for sessions:\n%s", pformat(rows_for_db_update)
|
||||
)
|
||||
stmt = db.beratung_einzelberatung.update().where(
|
||||
db.beratung_einzelberatung.c.beratung_id == sql.bindparam("b_beratung_id")
|
||||
db.beratung_einzelberatung.c.beratung_id == sa.bindparam("b_beratung_id")
|
||||
)
|
||||
conn.execute(stmt, rows_for_db_update)
|
||||
|
||||
@@ -599,7 +600,7 @@ def page_consulting_linking_companies(
|
||||
un_id: RecId | None,
|
||||
) -> list[LinkingConsultationsEntryCompany]:
|
||||
with db.ENGINE.connect() as conn:
|
||||
q_relevant_companies = sql.select(
|
||||
q_relevant_companies = sa.select(
|
||||
db.grunderfassung_unternehmen.c.un_id,
|
||||
db.grunderfassung_unternehmen.c.Partnersuche__un_suche,
|
||||
).where(
|
||||
@@ -613,7 +614,7 @@ def page_consulting_linking_companies(
|
||||
|
||||
q_relevant_companies = q_relevant_companies.subquery("relevant_companies")
|
||||
|
||||
stmt = sql.select(
|
||||
stmt = sa.select(
|
||||
q_relevant_companies.c.un_id,
|
||||
db.ext_crm_master_attach.c.ma_unternehmensname,
|
||||
).select_from(
|
||||
@@ -650,7 +651,7 @@ def page_consulting_linking_persons(
|
||||
# if un_id None: list all persons
|
||||
# else: list just the persons associated with the company
|
||||
|
||||
person_select = sql.select(
|
||||
person_select = sa.select(
|
||||
db.grunderfassung_personen.c.pers_id,
|
||||
db.grunderfassung_personen.c.Stammdaten__name,
|
||||
db.grunderfassung_personen.c.Stammdaten__vorname,
|
||||
@@ -698,7 +699,7 @@ def companyprofile_page_get_consultations(
|
||||
un_id: RecId,
|
||||
) -> CompanyProfileConsultations:
|
||||
logger.debug("[Call backend] _companyprofile_page_get_consultations")
|
||||
stmt = sql.select(
|
||||
stmt = sa.select(
|
||||
db.beratung_vorgang.c.vorgang_id,
|
||||
db.beratung_vorgang.c.aktualisiert,
|
||||
db.beratung_vorgang.c.titel,
|
||||
@@ -746,10 +747,42 @@ def companyprofile_page_get_consultations(
|
||||
)
|
||||
|
||||
|
||||
# // initial recording interaction
|
||||
@wrap_result(10)
|
||||
def initrec_link_person_company(
|
||||
un_id: RecId,
|
||||
pers_id: RecId,
|
||||
unlink: bool,
|
||||
) -> None:
|
||||
if unlink:
|
||||
deleted_ts = datetime.datetime.now(tz=datetime.UTC)
|
||||
stmt = (
|
||||
sa.update(db.zuordnung_personen_unternehmen)
|
||||
.where(
|
||||
db.zuordnung_personen_unternehmen.c.un_id == un_id,
|
||||
db.zuordnung_personen_unternehmen.c.pers_id == pers_id,
|
||||
db.zuordnung_personen_unternehmen.c.gueltig_bis.is_(None),
|
||||
)
|
||||
.values(gueltig_bis=deleted_ts)
|
||||
)
|
||||
else:
|
||||
stmt = (
|
||||
sqlite_insert(db.zuordnung_personen_unternehmen)
|
||||
.values(un_id=un_id, pers_id=pers_id)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=["un_id", "pers_id"],
|
||||
index_where=sa.text("gueltig_bis IS NULL"),
|
||||
)
|
||||
)
|
||||
|
||||
with db.ENGINE.begin() as conn:
|
||||
conn.execute(stmt)
|
||||
|
||||
|
||||
# // main page interaction
|
||||
def _main_page_get_company_list() -> list[MainPageEntry]:
|
||||
logger.debug("[Call backend] get_company_list")
|
||||
stmt = sql.select(
|
||||
stmt = sa.select(
|
||||
db.grunderfassung_unternehmen.c.un_id,
|
||||
db.grunderfassung_unternehmen.c.Partnersuche__un_suche,
|
||||
db.grunderfassung_unternehmen.c.Metadaten_aktualisierung,
|
||||
@@ -785,7 +818,7 @@ def _main_page_get_company_list() -> list[MainPageEntry]:
|
||||
|
||||
def _main_page_get_person_list() -> list[MainPageEntry]:
|
||||
logger.debug("[Call backend] get_company_list")
|
||||
stmt = sql.select(
|
||||
stmt = sa.select(
|
||||
db.grunderfassung_personen.c.pers_id,
|
||||
db.grunderfassung_personen.c.Stammdaten__vorname,
|
||||
db.grunderfassung_personen.c.Stammdaten__name,
|
||||
|
||||
@@ -248,6 +248,7 @@ class AutoForm_State(PageState[Module]):
|
||||
class Page_InitRecPerson_State(PageState[Module]):
|
||||
session: Session
|
||||
pers_id: RecId | None = None
|
||||
un_id: RecId | None = None
|
||||
locked: bool
|
||||
|
||||
|
||||
|
||||
+18
-7
@@ -3149,6 +3149,7 @@ class Page_InitRecCompany(QWidget):
|
||||
req_state = Page_InitRecPerson_State(
|
||||
session=self.STATE.session,
|
||||
pers_id=None,
|
||||
un_id=self.STATE.un_id,
|
||||
locked=False,
|
||||
)
|
||||
logger_gui.debug("[Page -- InitRec Company] State to call: %s", req_state)
|
||||
@@ -3365,6 +3366,7 @@ class Page_InitRecPerson(QWidget):
|
||||
def _auto_form_updated(self) -> None:
|
||||
self._sync_GUI_to_state()
|
||||
self._sync_state_to_GUI("banners")
|
||||
# TODO saving logic to connect company and person if needed
|
||||
|
||||
def reset_form(self) -> None:
|
||||
self.auto_form.reset_form()
|
||||
@@ -4318,15 +4320,24 @@ class Page_Consulting(QWidget):
|
||||
# .exec() öffnet das Fenster modal (blockiert das Hauptfenster)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
# Hier hast du am Ende beide (oder nur eine) Entitäten auswertbar vorliegen:
|
||||
firma = dialog.gewaehltes_unternehmen
|
||||
person = dialog.gewaehlte_person
|
||||
state = dialog.get_state()
|
||||
un_id = state.un_id
|
||||
pers_id = state.pers_id
|
||||
|
||||
comp_name = firma["name"] if firma else "Keine"
|
||||
person_name = person["name"] if person else "Keine"
|
||||
# TODO add infos to DB table "Beratung_Vorgang"
|
||||
assert self.STATE.vorgang_id is not None, (
|
||||
"cannot link consulting process which is not already saved"
|
||||
)
|
||||
|
||||
# firma = dialog.gewaehltes_unternehmen
|
||||
# person = dialog.gewaehlte_person
|
||||
|
||||
# comp_name = firma["name"] if firma else "Keine"
|
||||
# person_name = person["name"] if person else "Keine"
|
||||
logger_page_consulting.info(
|
||||
"[Consulting Page] Firme gewählt: %s, Person gewählt: %s",
|
||||
comp_name,
|
||||
person_name,
|
||||
"[Consulting Page] Company selected (ID): %s, Person selected (ID): %s",
|
||||
un_id,
|
||||
pers_id,
|
||||
)
|
||||
|
||||
# 1. TODO: Datenbank-Update ausführen (Fremdschlüssel setzen)
|
||||
|
||||
Reference in New Issue
Block a user