Skip to content

Commit

Permalink
Merge pull request #571 from maykinmedia/issue/#568-count
Browse files Browse the repository at this point in the history
🐛 #568 - fix: correct count
  • Loading branch information
SilviaAmAm authored Jan 14, 2025
2 parents 422d34b + 71cacb0 commit 3a8b11b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
12 changes: 12 additions & 0 deletions backend/src/openarchiefbeheer/destruction/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,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
Expand All @@ -455,8 +459,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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
)
1 change: 1 addition & 0 deletions frontend/src/fixtures/destructionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DestructionList>(
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/api/destructionLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export function useSecondaryNavigation(): ToolbarItem[] {
} = useRouteLoaderData(
"destruction-list:detail",
) as DestructionListDetailContext;

const confirm = useConfirm();
const prompt = usePrompt();
const formDialog = useFormDialog();
Expand Down Expand Up @@ -335,7 +334,7 @@ export function useSecondaryNavigation(): ToolbarItem[] {
onClick: () =>
formDialog<DestructionListNameFormType>(
"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",
Expand Down

0 comments on commit 3a8b11b

Please sign in to comment.