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

🐛 #568 - fix: correct count #571

Open
wants to merge 5 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
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 @@ -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
Expand All @@ -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(
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],
)
Xaohs marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -63,7 +63,6 @@ export function useSecondaryNavigation(): ToolbarItem[] {
} = useRouteLoaderData(
"destruction-list:detail",
) as DestructionListDetailContext;

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