diff --git a/backend/src/openarchiefbeheer/destruction/models.py b/backend/src/openarchiefbeheer/destruction/models.py index 0605775d..7bc9cd7b 100644 --- a/backend/src/openarchiefbeheer/destruction/models.py +++ b/backend/src/openarchiefbeheer/destruction/models.py @@ -222,8 +222,48 @@ def abort_destruction(self) -> None: self.processing_status = InternalStatus.new self.save() + def _get_user_data(self, log: TimelineLog | None) -> list[str]: + if not log: + return ["", ""] + + user_data = log.extra_data["user"] + + return [ + f"{user_data["first_name"]} {user_data["last_name"]} ({user_data["username"]})", + ", ".join(log.extra_data["user_groups"]), + ] + def _make_deleted_zaken_sheet(self, workbook: xlsxwriter.Workbook) -> None: - general_info_column_names = [] + worksheet = workbook.add_worksheet(name=gettext("Deleted zaken")) + + general_info_column_names = [ + gettext("Date/Time of deletion"), + gettext("User who started the deletion"), + gettext("Groups"), + gettext("Number of deleted cases"), + ] + worksheet.write_row(0, 0, general_info_column_names) + + destruction_log = ( + TimelineLog.objects.for_object(self) + .filter(template="logging/destruction_list_deletion_triggered.txt") + .order_by("timestamp") + .last() + ) + user_data = self._get_user_data(destruction_log) + + general_info_data = [ + self.end.astimezone(tz=timezone.get_default_timezone()).isoformat( + sep=" ", timespec="minutes" + ), + *user_data, + self.items.filter( + processing_status=InternalStatus.succeeded, + status=ListItemStatus.suggested, + ).count(), + ] + worksheet.write_row(1, 0, general_info_data) + worksheet.write_row(2, 0, []) # Add an empty row for readability column_names = [ "Zaaktype UUID", @@ -235,9 +275,7 @@ def _make_deleted_zaken_sheet(self, workbook: xlsxwriter.Workbook) -> None: "Selectielijst Procestype", "Resultaat", ] - - worksheet = workbook.add_worksheet(name=gettext("Deleted zaken")) - worksheet.write_row(0, 0, column_names) + worksheet.write_row(3, 0, column_names) for row_count, item in enumerate( self.items.filter(processing_status=InternalStatus.succeeded).iterator( @@ -256,7 +294,7 @@ def _make_deleted_zaken_sheet(self, workbook: xlsxwriter.Workbook) -> None: resultaat["resultaattype"]["omschrijving"] if resultaat else "", ] - worksheet.write_row(row_count + 1, 0, data) + worksheet.write_row(row_count + 4, 0, data) def _make_review_process_sheet(self, workbook: xlsxwriter.Workbook) -> None: column_names = [