diff --git a/src/open_inwoner/openzaak/api_models.py b/src/open_inwoner/openzaak/api_models.py index 9ed56f4331..e4b7b73207 100644 --- a/src/open_inwoner/openzaak/api_models.py +++ b/src/open_inwoner/openzaak/api_models.py @@ -82,6 +82,7 @@ def process_data(self) -> dict: "current_status": status_translate.from_glom( self, "status.statustype.omschrijving", default="" ), + "zaaktype_config": getattr(self, "zaaktype_config", None), "statustype_config": getattr(self, "statustype_config", None), "case_type": "Zaak", } diff --git a/src/open_inwoner/openzaak/cases.py b/src/open_inwoner/openzaak/cases.py index 46092926fc..d2e539518a 100644 --- a/src/open_inwoner/openzaak/cases.py +++ b/src/open_inwoner/openzaak/cases.py @@ -14,7 +14,7 @@ from .api_models import Resultaat, Rol, Status, Zaak, ZaakInformatieObject from .catalog import fetch_single_case_type, fetch_single_status_type from .clients import build_client -from .models import OpenZaakConfig, ZaakTypeStatusTypeConfig +from .models import OpenZaakConfig, ZaakTypeConfig, ZaakTypeStatusTypeConfig from .utils import is_zaak_visible logger = logging.getLogger(__name__) @@ -403,6 +403,21 @@ def resolve_status_type(case: Zaak) -> None: case.status.statustype = fetch_single_status_type(statustype_url) +def add_zaak_type_config(case: Zaak) -> None: + """ + Add `ZaakTypeConfig` corresponding to the zaaktype type url of the case + + Note: must be called after `resolve_zaak_type` since we're using the `uuid` and + `identificatie` from `case.zaaktype` + """ + try: + case.zaaktype_config = ZaakTypeConfig.objects.filter_case_type( + case.zaaktype + ).get() + except ZaakTypeConfig.DoesNotExist: + pass + + def add_status_type_config(case: Zaak) -> None: """ Add `ZaakTypeStatusTypeConfig` corresponding to the status type url of the case @@ -412,9 +427,10 @@ def add_status_type_config(case: Zaak) -> None: """ try: case.statustype_config = ZaakTypeStatusTypeConfig.objects.get( - statustype_url=case.status.statustype.url + zaaktype_config=case.zaaktype_config, + statustype_url=case.status.statustype.url, ) - except ZaakTypeStatusTypeConfig.DoesNotExist: + except (AttributeError, ZaakTypeStatusTypeConfig.DoesNotExist): pass @@ -433,6 +449,7 @@ def preprocess_data(cases: list[Zaak]) -> list[Zaak]: for case in cases: resolve_status(case) resolve_status_type(case) + add_zaak_type_config(case) add_status_type_config(case) cases.sort(key=lambda case: case.startdatum, reverse=True) diff --git a/src/open_inwoner/openzaak/tests/test_cases.py b/src/open_inwoner/openzaak/tests/test_cases.py index 6dd7e17a55..9bade0bba5 100644 --- a/src/open_inwoner/openzaak/tests/test_cases.py +++ b/src/open_inwoner/openzaak/tests/test_cases.py @@ -25,8 +25,10 @@ from ..constants import StatusIndicators from ..models import OpenZaakConfig from .factories import ( + CatalogusConfigFactory, ServiceFactory, StatusTranslationFactory, + ZaakTypeConfigFactory, ZaakTypeStatusTypeConfigFactory, ) from .mocks import ESuiteData @@ -163,6 +165,7 @@ def setUpTestData(cls): "schemas/ZaakType", url=f"{CATALOGI_ROOT}zaaktypen/53340e34-7581-4b04-884f", omschrijving="Coffee zaaktype", + identificatie="ZAAK-2022-0000000001", catalogus=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a", vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.openbaar, indicatieInternOfExtern="extern", @@ -195,8 +198,16 @@ def setUpTestData(cls): isEindstatus=True, ) + cls.catalogus_config = CatalogusConfigFactory.create( + url=cls.zaaktype["catalogus"] + ) + cls.zaaktype_config1 = ZaakTypeConfigFactory.create( + urls=[cls.zaaktype["url"]], + identificatie=cls.zaaktype["identificatie"], + catalogus=cls.catalogus_config, + ) cls.zt_statustype_config1 = ZaakTypeStatusTypeConfigFactory.create( - zaaktype_config__identificatie="ZAAK-2022-0000000001", + zaaktype_config=cls.zaaktype_config1, statustype_url=cls.status_type1["url"], status_indicator=StatusIndicators.warning, status_indicator_text="U moet documenten toevoegen", @@ -376,6 +387,19 @@ def _setUpMocks(self, m): def test_list_cases(self, m): self._setUpMocks(m) + # Added for https://taiga.maykinmedia.nl/project/open-inwoner/task/1904 + # In eSuite it is possible to reuse a StatusType for multiple ZaakTypen, which + # led to errors when retrieving the ZaakTypeStatusTypeConfig. This duplicate + # config is added to verify that that issue was solved + ZaakTypeStatusTypeConfigFactory.create( + statustype_url=self.status_type1["url"], + status_indicator=StatusIndicators.warning, + status_indicator_text="U moet documenten toevoegen", + description="Lorem ipsum dolor sit amet", + call_to_action_url="https://example.com", + call_to_action_text="duplicate", + ) + response = self.app.get( self.inner_url, user=self.user, headers={"HX-Request": "true"} ) @@ -390,6 +414,7 @@ def test_list_cases(self, m): "identification": self.zaak2["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type1["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": self.zt_statustype_config1, "case_type": "Zaak", }, @@ -400,6 +425,7 @@ def test_list_cases(self, m): "identification": self.zaak1["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type1["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": self.zt_statustype_config1, "case_type": "Zaak", }, @@ -410,6 +436,7 @@ def test_list_cases(self, m): "identification": self.zaak3["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type2["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": None, "case_type": "Zaak", }, @@ -470,6 +497,7 @@ def test_list_cases_for_eherkenning_user(self, m): "identification": self.zaak_eherkenning2["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type1["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": self.zt_statustype_config1, "case_type": "Zaak", }, @@ -482,6 +510,7 @@ def test_list_cases_for_eherkenning_user(self, m): "identification": self.zaak_eherkenning1["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type1["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": self.zt_statustype_config1, "case_type": "Zaak", }, @@ -661,6 +690,7 @@ def test_list_cases_paginated(self, m): "identification": self.zaak2["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type1["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": self.zt_statustype_config1, "case_type": "Zaak", }, @@ -685,6 +715,7 @@ def test_list_cases_paginated(self, m): "identification": self.zaak1["identificatie"], "description": self.zaaktype["omschrijving"], "current_status": self.status_type1["omschrijving"], + "zaaktype_config": self.zaaktype_config1, "statustype_config": self.zt_statustype_config1, "case_type": "Zaak", },