Skip to content

Commit

Permalink
🐛 #568 - fix: correct count
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Roeland committed Dec 20, 2024
1 parent 916e481 commit 73dd7cf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 49 deletions.
49 changes: 23 additions & 26 deletions backend/src/openarchiefbeheer/destruction/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,29 @@
from django.db import transaction
from django.db.models import F, Q, QuerySet
from django.utils.translation import gettext_lazy as _

from drf_spectacular.plumbing import build_basic_type
from drf_spectacular.utils import OpenApiTypes, extend_schema_field
from requests.exceptions import HTTPError
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework.relations import SlugRelatedField

from openarchiefbeheer.accounts.api.serializers import UserSerializer
from openarchiefbeheer.accounts.models import User
from openarchiefbeheer.logging import logevent
from openarchiefbeheer.zaken.api.filtersets import ZaakFilterSet
from openarchiefbeheer.zaken.api.serializers import ZaakSerializer
from openarchiefbeheer.zaken.models import Zaak
from openarchiefbeheer.zaken.utils import retrieve_selectielijstklasse_resultaat
from openarchiefbeheer.zaken.utils import \
retrieve_selectielijstklasse_resultaat
from requests.exceptions import HTTPError
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework.relations import SlugRelatedField

from ..api.constants import MAX_NUMBER_CO_REVIEWERS
from ..constants import (
DestructionListItemAction,
InternalStatus,
ListItemStatus,
ListRole,
ListStatus,
ReviewDecisionChoices,
ZaakActionType,
)
from ..models import (
DestructionList,
DestructionListAssignee,
DestructionListCoReview,
DestructionListItem,
DestructionListItemReview,
DestructionListReview,
ReviewItemResponse,
ReviewResponse,
)
from ..constants import (DestructionListItemAction, InternalStatus,
ListItemStatus, ListRole, ListStatus,
ReviewDecisionChoices, ZaakActionType)
from ..models import (DestructionList, DestructionListAssignee,
DestructionListCoReview, DestructionListItem,
DestructionListItemReview, DestructionListReview,
ReviewItemResponse, ReviewResponse)
from ..signals import co_reviewers_added
from ..tasks import process_review_response

Expand Down Expand Up @@ -426,6 +413,11 @@ 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 +434,13 @@ class Meta:
"created",
"status_changed",
"planned_destruction_date",
"deletable_items_count"
)

def get_deletable_items_count(self, instance) -> int:
succeeded_count = instance.items.filter(processing_status=InternalStatus.succeeded).count()
total_count = instance.items.all().count()
return total_count - succeeded_count

class ZakenReviewSerializer(serializers.Serializer):
zaak_url = serializers.URLField(
Expand Down
34 changes: 11 additions & 23 deletions backend/src/openarchiefbeheer/destruction/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,19 @@
from django.db.models import QuerySet
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from privates.fields import PrivateMediaFileField
from slugify import slugify
from timeline_logger.models import TimelineLog

from openarchiefbeheer.accounts.models import User
from openarchiefbeheer.config.models import ArchiveConfig
from openarchiefbeheer.utils.results_store import ResultStore
from openarchiefbeheer.zaken.utils import (
delete_zaak_and_related_objects,
get_zaak_metadata,
)
from openarchiefbeheer.zaken.utils import (delete_zaak_and_related_objects,
get_zaak_metadata)
from privates.fields import PrivateMediaFileField
from slugify import slugify
from timeline_logger.models import TimelineLog

from .assignment_logic import STATE_MANAGER
from .constants import (
DestructionListItemAction,
InternalStatus,
ListItemStatus,
ListRole,
ListStatus,
ReviewDecisionChoices,
ZaakActionType,
)
from .constants import (DestructionListItemAction, InternalStatus,
ListItemStatus, ListRole, ListStatus,
ReviewDecisionChoices, ZaakActionType)
from .exceptions import ZaakArchiefactiedatumInFuture, ZaakNotFound
from .managers import DestructionListManager

Expand Down Expand Up @@ -244,11 +234,9 @@ def generate_destruction_report(self) -> None:
self.save()

def create_report_zaak(self) -> None:
from .utils import (
attach_report_to_zaak,
create_eio_destruction_report,
create_zaak_for_report,
)
from .utils import (attach_report_to_zaak,
create_eio_destruction_report,
create_zaak_for_report)

if self.processing_status == InternalStatus.succeeded:
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import asyncio

from asgiref.sync import sync_to_async
from django.test import tag
from openarchiefbeheer.utils.tests.e2e import browser_page
from openarchiefbeheer.utils.tests.gherkin import GherkinLikeTestCase

from ....constants import InternalStatus, 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=5)
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.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")

0 comments on commit 73dd7cf

Please sign in to comment.