diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index 90cd53ed76..012a5b976f 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -189,11 +189,14 @@ def get_context_data(self, **kwargs): self.case.zaaktype.url ) - # NOTE we cannot sort on the Status.datum_status_gezet (datetime) because eSuite + # NOTE we cannot always sort on the Status.datum_status_gezet (datetime) because eSuite # returns zeros as the time component of the datetime, so we're going with the # observation that on both OpenZaak and eSuite the returned list is ordered 'oldest-last' # here we want it 'oldest-first' so we reverse() it instead of sort()-ing - statuses.reverse() + if config.order_statuses_by_date_set: + statuses.sort(key=lambda s: s.datum_status_gezet) + else: + statuses.reverse() # get preview of second status if len(statuses) == 1: diff --git a/src/open_inwoner/openzaak/admin.py b/src/open_inwoner/openzaak/admin.py index 9c9f70f6f8..ffae93e571 100644 --- a/src/open_inwoner/openzaak/admin.py +++ b/src/open_inwoner/openzaak/admin.py @@ -70,6 +70,7 @@ class OpenZaakConfigAdmin(SingletonModelAdmin): "enable_categories_filtering_with_zaken", "zaken_filter_enabled", "use_zaak_omschrijving_as_title", + "order_statuses_by_date_set", ), }, ), diff --git a/src/open_inwoner/openzaak/migrations/0057_openzaakconfig_order_statusses_by_date_set.py b/src/open_inwoner/openzaak/migrations/0057_openzaakconfig_order_statusses_by_date_set.py new file mode 100644 index 0000000000..a8d76a8e49 --- /dev/null +++ b/src/open_inwoner/openzaak/migrations/0057_openzaakconfig_order_statusses_by_date_set.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.16 on 2024-10-15 10:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("openzaak", "0056_openzaakconfig_use_zaak_omschrijving_as_title"), + ] + + operations = [ + migrations.AddField( + model_name="openzaakconfig", + name="order_statuses_by_date_set", + field=models.BooleanField( + default=False, + help_text="If enabled, the statuses of a case are ordered based on 'datum_status_gezet'. If not enabled, we show the statuses in the reverse order they are returned via the API, this because the eSuite does not return the timestamps of the statuses (eSuite, but also works for Open Zaak).", + verbose_name="On the detail page of the case, order the statuses based on the date they have been set", + ), + ), + ] diff --git a/src/open_inwoner/openzaak/models.py b/src/open_inwoner/openzaak/models.py index dedd52e480..70d500e168 100644 --- a/src/open_inwoner/openzaak/models.py +++ b/src/open_inwoner/openzaak/models.py @@ -425,6 +425,19 @@ def form_service(self, service): default=False, ) + order_statuses_by_date_set = models.BooleanField( + verbose_name=_( + "On the detail page of the case, order the statuses based on the date they have been set" + ), + help_text=_( + "If enabled, the statuses of a case are ordered based on 'datum_status_gezet'. " + "If not enabled, we show the statuses in the reverse order they are returned via the API, " + "this because the eSuite does not return the timestamps of the statuses (eSuite, but also " + "works for Open Zaak)." + ), + default=False, + ) + title_text = models.TextField( verbose_name=_("Title text"), help_text=_( diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index 006339054b..a3e5d509d5 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -2485,3 +2485,48 @@ def test_objectcontactmoment_with_contactmoment_null(self, m, cm_client_mock): response = self.app.get(self.case_detail_url, user=self.eherkenning_user) self.assertEqual(response.status_code, 200) + + def test_zaak_status_ordering(self, m): + self._setUpMocks(m) + + status_type_intermediate = generate_oas_component_cached( + "ztc", + "schemas/StatusType", + url=f"{CATALOGI_ROOT}statustypen/625f373c-2828-49b3-9a29-bc36dc84d729", + zaaktype=self.zaaktype["url"], + catalogus=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a", + omschrijving="Intermediate request", + omschrijvingGeneriek="some content", + statustekst="Modified", + volgnummer=2, + isEindstatus=False, + ) + status_intermediate = generate_oas_component_cached( + "zrc", + "schemas/Status", + url=f"{ZAKEN_ROOT}statussen/07a4ae16-8eea-4a93-a01a-f822d7235d0c", + zaak=self.zaak["url"], + statustype=status_type_intermediate["url"], + datumStatusGezet="2021-02-12", + statustoelichting="", + ) + + for resource in [status_type_intermediate, status_intermediate]: + m.get(resource["url"], json=resource) + + m.get( + f"{ZAKEN_ROOT}statussen?zaak={self.zaak['url']}", + json=paginated_response( + [status_intermediate, self.status_new, self.status_finish] + ), + ) + + self.config.order_statuses_by_date_set = True + self.config.save() + + response = self.app.get(self.case_detail_url, user=self.user) + case = response.context.get("case") + + self.assertEqual(case["statuses"][0]["label"], "Registered") + self.assertEqual(case["statuses"][1]["label"], "Modified") + self.assertEqual(case["statuses"][2]["label"], "Finish")