diff --git a/backend/src/openarchiefbeheer/destruction/api/serializers.py b/backend/src/openarchiefbeheer/destruction/api/serializers.py index fc825618..f57d8fbe 100644 --- a/backend/src/openarchiefbeheer/destruction/api/serializers.py +++ b/backend/src/openarchiefbeheer/destruction/api/serializers.py @@ -426,6 +426,10 @@ class DestructionListReadSerializer(serializers.ModelSerializer): assignees = DestructionListAssigneeReadSerializer(many=True) author = UserSerializer(read_only=True) assignee = UserSerializer(read_only=True) + deletable_items_count = serializers.SerializerMethodField( + help_text=_("Number of items to be deleted"), + allow_null=True, + ) class Meta: model = DestructionList @@ -442,8 +446,16 @@ class Meta: "created", "status_changed", "planned_destruction_date", + "deletable_items_count", ) + def get_deletable_items_count(self, instance: DestructionList) -> int: + succeeded_count = instance.items.filter( + processing_status=InternalStatus.succeeded + ).count() + total_count = instance.items.filter(status=ListItemStatus.suggested).count() + return total_count - succeeded_count + class ZakenReviewSerializer(serializers.Serializer): zaak_url = serializers.URLField( diff --git a/backend/src/openarchiefbeheer/destruction/tests/e2e/issues/test_568_correct_count.py b/backend/src/openarchiefbeheer/destruction/tests/e2e/issues/test_568_correct_count.py new file mode 100644 index 00000000..02d400e5 --- /dev/null +++ b/backend/src/openarchiefbeheer/destruction/tests/e2e/issues/test_568_correct_count.py @@ -0,0 +1,64 @@ +from django.test import tag + +from openarchiefbeheer.utils.tests.e2e import browser_page +from openarchiefbeheer.utils.tests.gherkin import GherkinLikeTestCase + +from ....constants import InternalStatus, ListItemStatus, ListStatus + + +@tag("e2e") +@tag("gh-568") +class Issue568CorrectCount(GherkinLikeTestCase): + async def test_destruction_fails_with_incorrect_count(self): + async with browser_page() as page: + zaken = await self.given.zaken_are_indexed(amount=6) + await self.given.record_manager_exists() + + destruction_list = await self.given.list_exists( + name="Destruction list to check count for", + status=ListStatus.ready_to_delete, + processing_status=InternalStatus.failed, + zaken=[], + ) + await self.given.list_item_exists( + destruction_list=destruction_list, + processing_status=InternalStatus.new, + zaak=zaken[0], + ) + await self.given.list_item_exists( + destruction_list=destruction_list, + processing_status=InternalStatus.failed, + zaak=zaken[1], + ) + await self.given.list_item_exists( + destruction_list=destruction_list, + processing_status=InternalStatus.processing, + zaak=zaken[2], + ) + await self.given.list_item_exists( + destruction_list=destruction_list, + processing_status=InternalStatus.queued, + zaak=zaken[3], + ) + await self.given.list_item_exists( + destruction_list=destruction_list, + processing_status=InternalStatus.succeeded, + zaak=zaken[4], + ) + await self.given.list_item_exists( + destruction_list=destruction_list, + status=ListItemStatus.removed, + processing_status=InternalStatus.new, + zaak=zaken[5], + ) + + await self.when.record_manager_logs_in(page) + await self.then.path_should_be(page, "/destruction-lists") + + await self.when.user_clicks_button( + page, "Destruction list to check count for" + ) + await self.when.user_clicks_button(page, "Vernietigen herstarten") + await self.then.page_should_contain_text( + page, "U staat op het punt om 4 zaken definitief te vernietigen" + ) diff --git a/frontend/src/fixtures/destructionList.ts b/frontend/src/fixtures/destructionList.ts index a1457bbe..f0ef8782 100644 --- a/frontend/src/fixtures/destructionList.ts +++ b/frontend/src/fixtures/destructionList.ts @@ -20,6 +20,7 @@ export const FIXTURE_DESTRUCTION_LIST: DestructionList = { assignee: defaultAssignees[0].user, created: "2024-07-11T16:57", statusChanged: "2024-07-11:16:57", + deletableItemsCount: 0, }; export const destructionListFactory = createObjectFactory( diff --git a/frontend/src/lib/api/destructionLists.ts b/frontend/src/lib/api/destructionLists.ts index 11f921f3..eedf0d29 100644 --- a/frontend/src/lib/api/destructionLists.ts +++ b/frontend/src/lib/api/destructionLists.ts @@ -13,12 +13,13 @@ export type DestructionList = { author: User; comment: string; containsSensitiveInfo: boolean; - plannedDestructionDate: string | null; created: string; + plannedDestructionDate: string | null; name: string; status: DestructionListStatus; processingStatus: ProcessingStatus; statusChanged: string | null; + deletableItemsCount: number; uuid: string; }; diff --git a/frontend/src/pages/destructionlist/detail/hooks/useSecondaryNavigation.tsx b/frontend/src/pages/destructionlist/detail/hooks/useSecondaryNavigation.tsx index 6471f736..ee066b1b 100644 --- a/frontend/src/pages/destructionlist/detail/hooks/useSecondaryNavigation.tsx +++ b/frontend/src/pages/destructionlist/detail/hooks/useSecondaryNavigation.tsx @@ -63,7 +63,6 @@ export function useSecondaryNavigation(): ToolbarItem[] { } = useRouteLoaderData( "destruction-list:detail", ) as DestructionListDetailContext; - const confirm = useConfirm(); const prompt = usePrompt(); const formDialog = useFormDialog(); @@ -284,7 +283,7 @@ export function useSecondaryNavigation(): ToolbarItem[] { onClick: () => formDialog( "Zaken definitief vernietigen", - `U staat op het punt om ${destructionListItems.count} zaken definitief te vernietigen`, + `U staat op het punt om ${destructionList.deletableItemsCount} zaken definitief te vernietigen`, [ { label: "Type naam van de lijst ter bevestiging",