diff --git a/backend/src/openarchiefbeheer/logging/logevent.py b/backend/src/openarchiefbeheer/logging/logevent.py index 36c8ca9d..2e4feae6 100644 --- a/backend/src/openarchiefbeheer/logging/logevent.py +++ b/backend/src/openarchiefbeheer/logging/logevent.py @@ -1,6 +1,6 @@ import traceback -from django.db.models import Model +from django.db.models import Max, Min, Model from timeline_logger.models import TimelineLog @@ -13,6 +13,10 @@ DestructionListReview, ReviewDecisionChoices, ) +from openarchiefbeheer.zaken.utils import ( + format_resultaten_choices, + format_zaaktype_choices, +) def _create_log( @@ -54,6 +58,47 @@ def destruction_list_created( ) +def destruction_list_ready_for_first_review( + destruction_list: DestructionList, user: User +) -> None: + + extra_data = { + "zaaktypen": format_zaaktype_choices( + destruction_list.items.distinct("zaak__zaaktype").values_list( + "zaak___expand__zaaktype", flat=True + ) + ), + "resultaten": format_resultaten_choices( + destruction_list.items.distinct("zaak__resultaat") + .values_list("zaak___expand__resultaat", flat=True) + .distinct() + ), + "archiefnominaties": list( + destruction_list.items.distinct("zaak__archiefnominatie").values_list( + "zaak__archiefnominatie", flat=True + ) + ), + "comment": destruction_list.comment, + "number_of_zaken": destruction_list.items.count(), + } + + items_max_min = destruction_list.items.aggregate( + Min("zaak__archiefactiedatum"), Max("zaak__archiefactiedatum") + ) + if archiefactiedatum_min := items_max_min.get("zaak__archiefactiedatum__min"): + extra_data["min_archiefactiedatum"] = archiefactiedatum_min + + if archiefactiedatum_max := items_max_min.get("zaak__archiefactiedatum__max"): + extra_data["max_archiefactiedatum"] = archiefactiedatum_max + + _create_log( + model=destruction_list, + event="destruction_list_ready_for_first_review", + user=user, + extra_data=extra_data, + ) + + def destruction_list_updated(destruction_list: DestructionList, user: User) -> None: _create_log(model=destruction_list, event="destruction_list_updated", user=user) diff --git a/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_ready_for_first_review.txt b/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_ready_for_first_review.txt new file mode 100644 index 00000000..6939e2cc --- /dev/null +++ b/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_ready_for_first_review.txt @@ -0,0 +1,3 @@ +{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name groups=log.extra_data.user_groups|join:", " record_manager=log.user comment=log.extra_data.comment count counter=log.extra_data.user_groups|length %} +User {{ record_manager }} (member of group {{ groups }}) has marked the destruction list "{{ list_name }}" as ready to review.{% plural %}User {{ record_manager }} (member of groups {{ groups }}) has marked the destruction list "{{ list_name }}" as ready to review. +{% endblocktranslate %} \ No newline at end of file diff --git a/backend/src/openarchiefbeheer/zaken/utils.py b/backend/src/openarchiefbeheer/zaken/utils.py index 072e6782..ef13bf3a 100644 --- a/backend/src/openarchiefbeheer/zaken/utils.py +++ b/backend/src/openarchiefbeheer/zaken/utils.py @@ -127,6 +127,17 @@ def format_selectielijstklasse_choice(resultaat: Resultaat) -> DropDownChoice: } +def format_resultaten_choices(resultaten: list[dict]) -> DropDownChoice: + result = [ + { + "value": resultaat["url"], + "label": resultaat.get("toelichting", resultaat["uuid"]), + } + for resultaat in resultaten + ] + return result + + @lru_cache def retrieve_selectielijstklasse_choices(query_params: HashableDict | None) -> list: config = APIConfig.get_solo()