Skip to content

Commit

Permalink
Merge pull request #527 from maykinmedia/feature/504-improve-destruct…
Browse files Browse the repository at this point in the history
…ion-report

[#504] Improve destruction report
  • Loading branch information
SilviaAmAm authored Dec 5, 2024
2 parents f28aec9 + 6ac8671 commit 7929213
Show file tree
Hide file tree
Showing 14 changed files with 754 additions and 363 deletions.
552 changes: 306 additions & 246 deletions backend/src/openarchiefbeheer/conf/locale/nl/LC_MESSAGES/django.po

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions backend/src/openarchiefbeheer/destruction/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ def perform_destroy(self, instance: DestructionList) -> None:
% {"destruction_date": destruction_date.strftime("%d/%m/%Y")}
)

logevent.destruction_list_deletion_triggered(instance, self.request.user)

if instance.processing_status == InternalStatus.new:
instance.planned_destruction_date = today + timedelta(days=WAITING_PERIOD)
instance.save()
Expand Down
43 changes: 38 additions & 5 deletions backend/src/openarchiefbeheer/destruction/destruction_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
from xlsxwriter.worksheet import Worksheet

from openarchiefbeheer.accounts.utils import format_user, format_user_groups
from openarchiefbeheer.logging.logevent import destruction_list_reviewed
from openarchiefbeheer.logging.utils import get_event_template, get_readable_timestamp
from openarchiefbeheer.logging.logevent import (
destruction_list_deletion_triggered,
destruction_list_reviewed,
)
from openarchiefbeheer.logging.utils import get_event_template
from openarchiefbeheer.utils.formatting import get_readable_timestamp
from openarchiefbeheer.zaken.api.constants import ZAAK_METADATA_FIELDS_MAPPINGS

from .constants import InternalStatus
from .constants import InternalStatus, ListItemStatus
from .models import DestructionList


Expand Down Expand Up @@ -41,13 +45,41 @@ def add_review_process_table(
data = [
format_user_groups(log.extra_data["user_groups"]),
format_user(log.extra_data["user"]),
get_readable_timestamp(log),
get_readable_timestamp(log.timestamp),
# This column is not useful, since we are filtering on approved reviews.
# But it was specifically requested.
_("Has approved"),
]
worksheet.write_row(start_row + row_count + 1, 0, data)

def add_general_info_table(self, worksheet: Worksheet, start_row: int = 0) -> None:
column_names = [
_("Date/Time of deletion"),
_("User who started the deletion"),
_("Groups"),
_("Number of deleted cases"),
]
worksheet.write_row(start_row, 0, column_names)

log = (
TimelineLog.objects.for_object(self.destruction_list)
.filter(template=get_event_template(destruction_list_deletion_triggered))
.order_by("timestamp")
.last()
)
number_of_cases = self.destruction_list.items.filter(
processing_status=InternalStatus.succeeded,
status=ListItemStatus.suggested,
).count()

general_info_data = [
get_readable_timestamp(self.destruction_list.end),
format_user(log.extra_data["user"]) if log else "",
format_user_groups(log.extra_data["user_groups"]) if log else "",
number_of_cases,
]
worksheet.write_row(start_row + 1, 0, general_info_data)

def add_zaken_table(self, worksheet: Worksheet, start_row: int = 0) -> None:
worksheet.write_row(
start_row, 0, [field["name"] for field in ZAAK_METADATA_FIELDS_MAPPINGS]
Expand All @@ -70,7 +102,8 @@ def generate_destruction_report(self, file: IO) -> None:
worksheet_zaken = workbook.add_worksheet(name=_("Deleted zaken"))
worksheet_review_process = workbook.add_worksheet(name=_("Review process"))

self.add_zaken_table(worksheet_zaken)
self.add_general_info_table(worksheet_zaken)
self.add_zaken_table(worksheet_zaken, start_row=3)
self.add_review_process_table(worksheet_review_process)

workbook.close()
2 changes: 2 additions & 0 deletions backend/src/openarchiefbeheer/destruction/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def assign(assignee: "DestructionListAssignee") -> None:
def set_status(self, status: str) -> None:
self.status = status
self.status_changed = timezone.now()
if status == ListStatus.deleted:
self.end = timezone.now()
self.save()

def add_items(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from timeline_logger.models import TimelineLog

from openarchiefbeheer.accounts.tests.factories import UserFactory

Expand Down Expand Up @@ -222,3 +223,10 @@ def test_can_start_destruction_if_archiefactiedatum_in_the_future_but_removed(se
)

self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)

logs = TimelineLog.objects.for_object(destruction_list).filter(
template="logging/destruction_list_deletion_triggered.txt"
)

self.assertEqual(len(logs), 1)
self.assertEqual(logs[0].extra_data["user"]["username"], "record_manager")
Loading

0 comments on commit 7929213

Please sign in to comment.