Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#570] Add start of destruction time #575

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions backend/src/openarchiefbeheer/destruction/destruction_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def add_review_process_table(

def add_general_info_table(self, worksheet: Worksheet, start_row: int = 0) -> None:
column_names = [
_("Date/Time of deletion"),
_("User who started the deletion"),
# When the record manager starts the deletion process
_("Date/Time starting destruction"),
_("Date/Time of destruction"),
_("User who started the destruction"),
_("Groups"),
_("Number of deleted cases"),
]
Expand All @@ -73,6 +75,7 @@ def add_general_info_table(self, worksheet: Worksheet, start_row: int = 0) -> No
).count()

general_info_data = [
get_readable_timestamp(log.timestamp),
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 "",
Expand Down Expand Up @@ -100,10 +103,10 @@ def generate_destruction_report(self, file: IO) -> None:
workbook = xlsxwriter.Workbook(file.name, options={"in_memory": False})

worksheet_zaken = workbook.add_worksheet(name=_("Deleted zaken"))
worksheet_review_process = workbook.add_worksheet(name=_("Review process"))
worksheet_process_details = workbook.add_worksheet(name=_("Process details"))

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

workbook.close()
99 changes: 60 additions & 39 deletions backend/src/openarchiefbeheer/destruction/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ def test_generate_destruction_report(self):
status=ListStatus.deleted,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager)
with freeze_time("2024-12-01T12:00:00+01:00"):
logevent.destruction_list_deletion_triggered(
destruction_list, record_manager
)
DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
status=ListItemStatus.suggested,
Expand Down Expand Up @@ -397,27 +400,9 @@ def test_generate_destruction_report(self):
sheet_deleted_zaken = wb[gettext("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 7)
self.assertEqual(
rows[0][:4],
(
gettext("Date/Time of deletion"),
gettext("User who started the deletion"),
gettext("Groups"),
gettext("Number of deleted cases"),
),
)
self.assertEqual(
rows[1][:4],
(
"2024-12-02 12:00+01:00",
"John Doe (jdoe1)",
None,
3,
),
)
self.assertEqual(len(rows), 4)
self.assertEqual(
rows[3],
rows[0],
(
"Zaaktype UUID",
"Zaaktype Omschrijving",
Expand All @@ -430,7 +415,7 @@ def test_generate_destruction_report(self):
),
)
self.assertEqual(
rows[4],
rows[1],
(
"111-111-111",
"Tralala zaaktype",
Expand All @@ -443,7 +428,7 @@ def test_generate_destruction_report(self):
),
)
self.assertEqual(
rows[5],
rows[2],
(
"111-111-111",
"Tralala zaaktype",
Expand All @@ -456,7 +441,7 @@ def test_generate_destruction_report(self):
),
)
self.assertEqual(
rows[6],
rows[3],
(
"111-111-222",
"Tralala zaaktype",
Expand All @@ -469,8 +454,34 @@ def test_generate_destruction_report(self):
),
)

sheet_process_details = wb[gettext("Process details")]
rows = list(sheet_process_details.iter_rows(values_only=True))

self.assertEqual(
rows[0][:5],
(
gettext("Date/Time starting destruction"),
gettext("Date/Time of destruction"),
gettext("User who started the destruction"),
gettext("Groups"),
gettext("Number of deleted cases"),
),
)
self.assertEqual(
rows[1][:5],
(
"2024-12-01 12:00+01:00",
"2024-12-02 12:00+01:00",
"John Doe (jdoe1)",
None,
3,
),
)

def test_generate_destruction_report_with_cases_excluded_from_list(self):
author = UserFactory.create(post__can_start_destruction=True)
destruction_list = DestructionListFactory.create(
author=author,
status=ListStatus.deleted,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)
Expand Down Expand Up @@ -534,6 +545,7 @@ def test_generate_destruction_report_with_cases_excluded_from_list(self):
},
},
)
logevent.destruction_list_deletion_triggered(destruction_list, author)

destruction_list.generate_destruction_report()

Expand All @@ -543,9 +555,9 @@ def test_generate_destruction_report_with_cases_excluded_from_list(self):
sheet_deleted_zaken = wb[gettext("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 6)
self.assertEqual(len(rows), 3)
self.assertEqual(
rows[3],
rows[0],
(
"Zaaktype UUID",
"Zaaktype Omschrijving",
Expand All @@ -557,7 +569,7 @@ def test_generate_destruction_report_with_cases_excluded_from_list(self):
"Resultaat",
),
)
deleted_zaken_ids = sorted([rows[4][3], rows[5][3]])
deleted_zaken_ids = sorted([rows[1][3], rows[2][3]])
self.assertEqual(
deleted_zaken_ids,
["ZAAK-01", "ZAAK-03"],
Expand All @@ -580,30 +592,38 @@ def test_generate_destruction_report_with_multiple_logs(self):
status=ListStatus.deleted,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager1)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager2)
with freeze_time("2024-12-01T12:00:00+01:00"):
logevent.destruction_list_deletion_triggered(
destruction_list, record_manager1
)
with freeze_time("2024-12-01T12:30:00+01:00"):
logevent.destruction_list_deletion_triggered(
destruction_list, record_manager2
)

destruction_list.generate_destruction_report()

destruction_list.refresh_from_db()

wb = load_workbook(filename=destruction_list.destruction_report.path)
sheet_deleted_zaken = wb[gettext("Deleted zaken")]
sheet_deleted_zaken = wb[gettext("Process details")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 4)
self.assertEqual(len(rows), 4) # No reviews logs
self.assertEqual(
rows[0][:4],
rows[0][:5],
(
gettext("Date/Time of deletion"),
gettext("User who started the deletion"),
gettext("Date/Time starting destruction"),
gettext("Date/Time of destruction"),
gettext("User who started the destruction"),
gettext("Groups"),
gettext("Number of deleted cases"),
),
)
self.assertEqual(
rows[1][:4],
rows[1][:5],
(
"2024-12-01 12:30+01:00",
"2024-12-02 12:00+01:00",
"Jane Doe (jdoe2)",
None,
Expand Down Expand Up @@ -653,6 +673,7 @@ def test_generate_destruction_report_review_process(self):
logevent.destruction_list_reviewed(
destruction_list, review_reviewer_rejected, reviewer
) # A rejection (should NOT be present in the report)
logevent.destruction_list_deletion_triggered(destruction_list, author)
with freeze_time("2024-05-02T16:00:00+02:00"):
logevent.destruction_list_reviewed(
destruction_list, review_reviewer_accepted, reviewer
Expand All @@ -665,13 +686,13 @@ def test_generate_destruction_report_review_process(self):
destruction_list.generate_destruction_report()

wb = load_workbook(filename=destruction_list.destruction_report.path)
sheet_deleted_zaken = wb[gettext("Review process")]
sheet_deleted_zaken = wb[gettext("Process details")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 3)
self.assertEqual(len(rows), 6)

self.assertEqual(
rows[1],
rows[4][:4],
(
"Reviewer",
"John Doe (jdoe1)",
Expand All @@ -680,7 +701,7 @@ def test_generate_destruction_report_review_process(self):
),
)
self.assertEqual(
rows[2],
rows[5][:4],
(
"Archivist",
"Alice Wonderland (awonderland1)",
Expand Down
Loading
Loading