Skip to content

Commit 944ba71

Browse files
committed
[Venray #121] Support sorting the statusses on date set (Rx.mission, Open Zaak)
1 parent 1a967a0 commit 944ba71

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

src/open_inwoner/cms/cases/views/status.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,14 @@ def get_context_data(self, **kwargs):
200200
self.case.zaaktype.url
201201
)
202202

203-
# NOTE we cannot sort on the Status.datum_status_gezet (datetime) because eSuite
203+
# NOTE we cannot always sort on the Status.datum_status_gezet (datetime) because eSuite
204204
# returns zeros as the time component of the datetime, so we're going with the
205205
# observation that on both OpenZaak and eSuite the returned list is ordered 'oldest-last'
206206
# here we want it 'oldest-first' so we reverse() it instead of sort()-ing
207-
statuses.reverse()
207+
if config.order_statuses_by_date_set:
208+
statuses.sort(key=lambda s: s.datum_status_gezet)
209+
else:
210+
statuses.reverse()
208211

209212
# get preview of second status
210213
if len(statuses) == 1:

src/open_inwoner/openzaak/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class OpenZaakConfigAdmin(SingletonModelAdmin):
7070
"enable_categories_filtering_with_zaken",
7171
"zaken_filter_enabled",
7272
"use_zaak_omschrijving_as_title",
73+
"order_statuses_by_date_set",
7374
),
7475
},
7576
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.16 on 2024-10-15 10:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("openzaak", "0056_openzaakconfig_use_zaak_omschrijving_as_title"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="openzaakconfig",
15+
name="order_statuses_by_date_set",
16+
field=models.BooleanField(
17+
default=False,
18+
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).",
19+
verbose_name="On the detail page of the case, order the statuses based on the date they have been set",
20+
),
21+
),
22+
]

src/open_inwoner/openzaak/models.py

+13
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,19 @@ def form_service(self, service):
425425
default=False,
426426
)
427427

428+
order_statuses_by_date_set = models.BooleanField(
429+
verbose_name=_(
430+
"On the detail page of the case, order the statuses based on the date they have been set"
431+
),
432+
help_text=_(
433+
"If enabled, the statuses of a case are ordered based on 'datum_status_gezet'. "
434+
"If not enabled, we show the statuses in the reverse order they are returned via the API, "
435+
"this because the eSuite does not return the timestamps of the statuses (eSuite, but also "
436+
"works for Open Zaak)."
437+
),
438+
default=False,
439+
)
440+
428441
title_text = models.TextField(
429442
verbose_name=_("Title text"),
430443
help_text=_(

src/open_inwoner/openzaak/tests/test_case_detail.py

+45
Original file line numberDiff line numberDiff line change
@@ -2527,3 +2527,48 @@ def test_objectcontactmoment_with_contactmoment_null(self, m, cm_client_mock):
25272527
response = self.app.get(self.case_detail_url, user=self.eherkenning_user)
25282528

25292529
self.assertEqual(response.status_code, 200)
2530+
2531+
def test_zaak_status_ordering(self, m):
2532+
self._setUpMocks(m)
2533+
2534+
status_type_intermediate = generate_oas_component_cached(
2535+
"ztc",
2536+
"schemas/StatusType",
2537+
url=f"{CATALOGI_ROOT}statustypen/625f373c-2828-49b3-9a29-bc36dc84d729",
2538+
zaaktype=self.zaaktype["url"],
2539+
catalogus=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a",
2540+
omschrijving="Intermediate request",
2541+
omschrijvingGeneriek="some content",
2542+
statustekst="Modified",
2543+
volgnummer=2,
2544+
isEindstatus=False,
2545+
)
2546+
status_intermediate = generate_oas_component_cached(
2547+
"zrc",
2548+
"schemas/Status",
2549+
url=f"{ZAKEN_ROOT}statussen/07a4ae16-8eea-4a93-a01a-f822d7235d0c",
2550+
zaak=self.zaak["url"],
2551+
statustype=status_type_intermediate["url"],
2552+
datumStatusGezet="2021-02-12",
2553+
statustoelichting="",
2554+
)
2555+
2556+
for resource in [status_type_intermediate, status_intermediate]:
2557+
m.get(resource["url"], json=resource)
2558+
2559+
m.get(
2560+
f"{ZAKEN_ROOT}statussen?zaak={self.zaak['url']}",
2561+
json=paginated_response(
2562+
[status_intermediate, self.status_new, self.status_finish]
2563+
),
2564+
)
2565+
2566+
self.config.order_statuses_by_date_set = True
2567+
self.config.save()
2568+
2569+
response = self.app.get(self.case_detail_url, user=self.user)
2570+
case = response.context.get("case")
2571+
2572+
self.assertEqual(case["statuses"][0]["label"], "Registered")
2573+
self.assertEqual(case["statuses"][1]["label"], "Modified")
2574+
self.assertEqual(case["statuses"][2]["label"], "Finish")

0 commit comments

Comments
 (0)