generated from dopt-python/py311
refactoring and basic loading of existing consultations on the company profile
This commit is contained in:
@@ -10,9 +10,20 @@ from dopt_basics.result_pattern import wrap_result
|
||||
|
||||
from wce_crm import db
|
||||
from wce_crm.constants import TIMEZONE_CEST
|
||||
from wce_crm.data_models import Beratungsgespraech_Einzelgespraech, Beratungsgespraech_Vorgang
|
||||
from wce_crm.data_models import (
|
||||
Beratungsgespraech_Einzelgespraech,
|
||||
Beratungsgespraech_Vorgang,
|
||||
)
|
||||
from wce_crm.logging import logger_back as logger
|
||||
from wce_crm.types import CompanyInfo, ContactPersonInfo, InitRecType, MainPageEntry
|
||||
from wce_crm.types import (
|
||||
CompanyInfo,
|
||||
CompanyProfileConsultationEntry,
|
||||
CompanyProfileConsultations,
|
||||
ConsultingType,
|
||||
ContactPersonInfo,
|
||||
InitRecType,
|
||||
MainPageEntry,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from wce_crm.types import ConsId, ExtAnId, ExtMaId, RecId
|
||||
@@ -393,6 +404,59 @@ def page_consulting_from_db(
|
||||
return consultation_data
|
||||
|
||||
|
||||
# // consulting page interaction
|
||||
def companyprofile_page_get_consultations(
|
||||
un_id: RecId,
|
||||
) -> CompanyProfileConsultations:
|
||||
logger.debug("[Call backend] _companyprofile_page_get_consultations")
|
||||
stmt = sql.select(
|
||||
db.beratung_vorgang.c.vorgang_id,
|
||||
db.beratung_vorgang.c.aktualisiert,
|
||||
db.beratung_vorgang.c.titel,
|
||||
db.beratung_vorgang.c.beratungs_typ,
|
||||
).where(db.beratung_vorgang.c.un_id == un_id)
|
||||
|
||||
with db.ENGINE.connect() as conn:
|
||||
res = conn.execute(stmt)
|
||||
|
||||
cons_entries_pauschal: list[CompanyProfileConsultationEntry] = []
|
||||
cons_entries_individual: list[CompanyProfileConsultationEntry] = []
|
||||
|
||||
for entry in res.mappings():
|
||||
cons_id = entry["vorgang_id"]
|
||||
assert cons_id, "no VorgangID defined"
|
||||
|
||||
datetime_updated = cast(datetime.datetime, entry["aktualisiert"])
|
||||
datetime_updated = datetime_updated.astimezone(TIMEZONE_CEST)
|
||||
|
||||
base_title = entry["titel"]
|
||||
|
||||
_cons_type = entry["beratungs_typ"]
|
||||
cons_type = ConsultingType(_cons_type)
|
||||
|
||||
con_entry = CompanyProfileConsultationEntry(
|
||||
cons_id=cons_id,
|
||||
title=base_title,
|
||||
date_updated=datetime_updated,
|
||||
cons_type=cons_type,
|
||||
)
|
||||
|
||||
if cons_type is ConsultingType.PAUSCHAL:
|
||||
cons_entries_pauschal.append(con_entry)
|
||||
elif cons_type is ConsultingType.INDIVIDUAL:
|
||||
cons_entries_individual.append(con_entry)
|
||||
else:
|
||||
raise TypeError(f"Unknown consulting type: {_cons_type}")
|
||||
|
||||
cons_entries_pauschal.sort(key=lambda x: x.date_updated, reverse=True)
|
||||
cons_entries_individual.sort(key=lambda x: x.date_updated, reverse=True)
|
||||
|
||||
return CompanyProfileConsultations(
|
||||
pauschal=cons_entries_pauschal,
|
||||
individual=cons_entries_individual,
|
||||
)
|
||||
|
||||
|
||||
# // main page interaction
|
||||
def _main_page_get_company_list() -> list[MainPageEntry]:
|
||||
logger.debug("[Call backend] get_company_list")
|
||||
|
||||
Reference in New Issue
Block a user