switch to new data model with distinct company and person data

This commit is contained in:
2026-06-26 14:14:45 +02:00
parent b9427bc756
commit df93914942
9 changed files with 436 additions and 265 deletions
+62 -56
View File
@@ -58,7 +58,12 @@ from PySide6.QtWidgets import (
import wce_crm.constants
from wce_crm.backend import backend
from wce_crm.data_models import COLUMN_SEP, FlatBaseModel, Grunderfassung
from wce_crm.data_models import (
COLUMN_SEP,
FlatBaseModel,
Grunderfassung_Personen,
Grunderfassung_Unternehmen,
)
from wce_crm.form_defs import (
INITREC_COMP,
INITREC_PERSON,
@@ -1351,7 +1356,7 @@ class AutoForm(QWidget):
logger_auto_form.debug(
"Loaded data dict:\n%s Passing to Pydantic...", pformat(loaded_data)
)
model = Grunderfassung(**loaded_data)
model = self.cfg.model(**loaded_data)
logger_auto_form.debug("Loaded to Pydantic.")
logger_auto_form.debug("Convert to GUI structure...")
form_data = model.to_gui()
@@ -2081,35 +2086,33 @@ class NewEntrySelect_view(QWidget):
CONFIG_GRUNDERFASSUNG_UNTERNEHMEN: Final[AutoFormConfig] = AutoFormConfig(
model=Grunderfassung,
data_insert=backend.initrec_insert_initial_recording,
data_update=backend.initrec_update_initial_recording,
data_get=backend.initrec_get_initial_recording,
data_delete=backend.initrec_delete_initial_recording,
model=Grunderfassung_Unternehmen,
data_insert=backend.initrec_company_insert_initial_recording,
data_update=backend.initrec_company_update_initial_recording,
data_get=backend.initrec_company_get_initial_recording,
data_delete=backend.initrec_company_delete_initial_recording,
ignored_keys=(
"Metadaten_erstellung",
"Metadaten_aktualisierung",
"Metadaten_wiedereintrittsdatum",
),
form_fields=INITREC_COMP,
)
CONFIG_GRUNDERFASSUNG_PERSONEN: Final[AutoFormConfig] = AutoFormConfig(
model=Grunderfassung,
data_insert=backend.initrec_insert_initial_recording,
data_update=backend.initrec_update_initial_recording,
data_get=backend.initrec_get_initial_recording,
data_delete=backend.initrec_delete_initial_recording,
model=Grunderfassung_Personen,
data_insert=backend.initrec_person_insert_initial_recording,
data_update=backend.initrec_person_update_initial_recording,
data_get=backend.initrec_person_get_initial_recording,
data_delete=backend.initrec_person_delete_initial_recording,
ignored_keys=(
"Metadaten_erstellung",
"Metadaten_aktualisierung",
"Partnersuche",
),
form_fields=INITREC_PERSON,
)
CUSTOM_WIDGETS: Final[dict[str, type[CustomWidget]]] = {
"grunderfassung_suche": Grunderfassung_SuchWidget,
"grunderfassung_unternehmen_suche": Grunderfassung_SuchWidget,
}
@@ -2203,51 +2206,53 @@ class Page_InitRecCompany(QWidget):
self.search_widget_trigger = cast(
QLineEdit, search_widget.company_widgets["ma_unternehmensname"]
)
text_widget_set = search_widgets_by_key(
self.auto_form.widget_registry, f"Kontaktperson{COLUMN_SEP}KP_name_partner"
)
assert len(text_widget_set) == 1
self.text_widget_set = cast(QLineEdit, text_widget_set[0]["widget"])
self.search_widget_trigger.textChanged.connect(
self._custom_set_company_name_contact_person
)
# TODO check how this should be done with new architecture
# text_widget_set = search_widgets_by_key(
# self.auto_form.widget_registry, f"Kontaktperson{COLUMN_SEP}KP_name_partner"
# )
# assert len(text_widget_set) == 1
# self.text_widget_set = cast(QLineEdit, text_widget_set[0]["widget"])
# self.search_widget_trigger.textChanged.connect(
# self._custom_set_company_name_contact_person
# )
# ** 'Bundesland' only if 'Inland' selected in 'Stammdaten'
person_location = search_widgets_by_key(
self.auto_form.widget_registry, f"Stammdaten{COLUMN_SEP}aufenthaltsort"
)
assert len(person_location) == 1
self.person_location = cast(QComboBox, person_location[0]["widget"])
assert isinstance(self.person_location, QComboBox)
self.person_location.currentIndexChanged.connect(self._custom_county_selection)
# TODO check removal
# person_location = search_widgets_by_key(
# self.auto_form.widget_registry, f"Stammdaten{COLUMN_SEP}aufenthaltsort"
# )
# assert len(person_location) == 1
# self.person_location = cast(QComboBox, person_location[0]["widget"])
# assert isinstance(self.person_location, QComboBox)
# self.person_location.currentIndexChanged.connect(self._custom_county_selection)
selection_county = search_widgets_by_key(
self.auto_form.widget_registry, f"Stammdaten{COLUMN_SEP}bundesland"
)
assert len(selection_county) == 1
self.selection_county = cast(QComboBox, selection_county[0]["widget"])
assert isinstance(self.selection_county, QComboBox)
self.selection_county.setProperty("styleClass", "stempel")
self.selection_county.setEnabled(False)
# selection_county = search_widgets_by_key(
# self.auto_form.widget_registry, f"Stammdaten{COLUMN_SEP}bundesland"
# )
# assert len(selection_county) == 1
# self.selection_county = cast(QComboBox, selection_county[0]["widget"])
# assert isinstance(self.selection_county, QComboBox)
# self.selection_county.setProperty("styleClass", "stempel")
# self.selection_county.setEnabled(False)
def _custom_set_company_name_contact_person(self, value: str) -> None:
self.text_widget_set.setText(str(value))
# def _custom_set_company_name_contact_person(self, value: str) -> None:
# self.text_widget_set.setText(str(value))
def _custom_county_selection(self, idx: int) -> None:
value = self.person_location.itemData(idx)
if value == "Inland":
self.selection_county.setEnabled(True)
self.selection_county.setProperty("styleClass", "")
self.selection_county.style().unpolish(self.selection_county)
self.selection_county.style().polish(self.selection_county)
self.selection_county.update()
else:
self.selection_county.setCurrentIndex(0)
self.selection_county.setEnabled(False)
self.selection_county.setProperty("styleClass", "stempel")
self.selection_county.style().unpolish(self.selection_county)
self.selection_county.style().polish(self.selection_county)
self.selection_county.update()
# def _custom_county_selection(self, idx: int) -> None:
# value = self.person_location.itemData(idx)
# if value == "Inland":
# self.selection_county.setEnabled(True)
# self.selection_county.setProperty("styleClass", "")
# self.selection_county.style().unpolish(self.selection_county)
# self.selection_county.style().polish(self.selection_county)
# self.selection_county.update()
# else:
# self.selection_county.setCurrentIndex(0)
# self.selection_county.setEnabled(False)
# self.selection_county.setProperty("styleClass", "stempel")
# self.selection_county.style().unpolish(self.selection_county)
# self.selection_county.style().polish(self.selection_county)
# self.selection_county.update()
def reset_form(self) -> None:
self.auto_form.reset_form()
@@ -2330,6 +2335,7 @@ class Page_InitRecPerson(QWidget):
# --- CUSTOM LOGIC ---
# ** fill 'Kontaktperson -> Namen Unternehmen'
# TODO check how partners are selected with new architecture
# search_res = search_widgets_by_key(self.auto_form.widget_registry, "Partnersuche")
# assert len(search_res) == 1
# search_widget = cast(Grunderfassung_SuchWidget, search_res[0]["widget"])
@@ -2628,7 +2634,7 @@ class Page_CompanyProfile(QWidget):
self.current_id = id_
return
init_rec = backend.initrec_get_initial_recording(id_)
init_rec = backend.initrec_company_get_initial_recording(id_)
ma_id = cast(ExtMaId, init_rec["Partnersuche__un_suche"])
assert ma_id is not None, "no ma_id obtained"
comp_info = backend.initrec_comp_search_get_info(ma_id)