diff --git a/backend/src/openarchiefbeheer/destruction/api/serializers.py b/backend/src/openarchiefbeheer/destruction/api/serializers.py index 47ae80cf..48179aa8 100644 --- a/backend/src/openarchiefbeheer/destruction/api/serializers.py +++ b/backend/src/openarchiefbeheer/destruction/api/serializers.py @@ -15,7 +15,10 @@ from openarchiefbeheer.accounts.models import User from openarchiefbeheer.logging import logevent from openarchiefbeheer.zaken.api.filtersets import ZaakFilter -from openarchiefbeheer.zaken.api.serializers import ZaakSerializer +from openarchiefbeheer.zaken.api.serializers import ( + ZaakMetadataSerializer, + ZaakSerializer, +) from openarchiefbeheer.zaken.models import Zaak from openarchiefbeheer.zaken.utils import retrieve_selectielijstklasse_resultaat @@ -132,6 +135,7 @@ def validate(self, attrs: dict) -> dict: class DestructionListItemReadSerializer(serializers.ModelSerializer): zaak = ZaakSerializer(allow_null=True, read_only=True) + extra_zaak_data = ZaakMetadataSerializer(read_only=True, allow_null=True) class Meta: model = DestructionListItem diff --git a/backend/src/openarchiefbeheer/destruction/models.py b/backend/src/openarchiefbeheer/destruction/models.py index 45ee30fb..4dbd4b34 100644 --- a/backend/src/openarchiefbeheer/destruction/models.py +++ b/backend/src/openarchiefbeheer/destruction/models.py @@ -14,7 +14,10 @@ from openarchiefbeheer.accounts.models import User from openarchiefbeheer.config.models import ArchiveConfig from openarchiefbeheer.utils.results_store import ResultStore -from openarchiefbeheer.zaken.utils import delete_zaak_and_related_objects +from openarchiefbeheer.zaken.utils import ( + delete_zaak_and_related_objects, + get_zaak_metadata, +) from .assignment_logic import STATE_MANAGER from .constants import ( @@ -276,6 +279,7 @@ def _delete_zaak(self): def process_deletion(self) -> None: self.processing_status = InternalStatus.processing + self.extra_zaak_data = get_zaak_metadata(self.zaak) self.save() try: diff --git a/backend/src/openarchiefbeheer/zaken/api/serializers.py b/backend/src/openarchiefbeheer/zaken/api/serializers.py index f27d2a8c..4a1d082f 100644 --- a/backend/src/openarchiefbeheer/zaken/api/serializers.py +++ b/backend/src/openarchiefbeheer/zaken/api/serializers.py @@ -1,5 +1,6 @@ from django.utils.translation import gettext_lazy as _ +from drf_spectacular.utils import extend_schema_field from rest_framework import serializers from rest_framework.exceptions import ValidationError from rest_framework_gis.fields import GeometryField @@ -120,3 +121,30 @@ def validate(self, attrs): _("Multiple query parameters at the same time are not supported.") ) return attrs + + +class ZaakMetadataSerializer(serializers.ModelSerializer): + zaaktype = serializers.SerializerMethodField() + + class Meta: + model = Zaak + fields = ( + "url", + "einddatum", + "resultaat", + "startdatum", + "omschrijving", + "identificatie", + "zaaktype", + ) + + @extend_schema_field(serializers.JSONField) + def get_zaaktype(self, zaak: Zaak) -> dict | None: + zaaktype = zaak._expand["zaaktype"] + return { + "url": zaaktype["url"], + "omschrijving": zaaktype["omschrijving"], + "selectielijst_procestype": { + "nummer": zaaktype["selectielijst_procestype"]["nummer"] + }, + } diff --git a/backend/src/openarchiefbeheer/zaken/utils.py b/backend/src/openarchiefbeheer/zaken/utils.py index 5290347f..a415ea7f 100644 --- a/backend/src/openarchiefbeheer/zaken/utils.py +++ b/backend/src/openarchiefbeheer/zaken/utils.py @@ -356,3 +356,10 @@ def format_choice(item: dict) -> DropDownChoice: results += [format_choice(result) for result in page["results"]] return results + + +def get_zaak_metadata(zaak: Zaak) -> dict: + from .api.serializers import ZaakMetadataSerializer + + serializer = ZaakMetadataSerializer(instance=zaak) + return serializer.data