Skip to content

Commit

Permalink
✨ Add status to summary review request view
Browse files Browse the repository at this point in the history
  • Loading branch information
damm89 committed Feb 22, 2024
1 parent 46f9e92 commit feb3bb0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
11 changes: 7 additions & 4 deletions backend/src/zac/contrib/objects/kownsl/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from zac.core.api.serializers import ZaakEigenschapSerializer, ZaakSerializer
from zac.elasticsearch.drf_api.serializers import ESListZaakDocumentSerializer

from ..constants import KownslTypes
from ..constants import KownslStatus, KownslTypes
from ..data import (
Advice,
Approval,
Expand Down Expand Up @@ -578,6 +578,11 @@ class ZaakRevReqSummarySerializer(APIModelSerializer):
help_text=_("The number of completed requests."),
source="get_completed",
)
status = serializers.ChoiceField(
help_text=_("The status of the review request"),
source="get_status",
choices=KownslStatus.choices,
)

class Meta:
model = ReviewRequest
Expand All @@ -590,6 +595,7 @@ class Meta:
"lock_reason",
"num_assigned_users",
"review_type",
"status",
)

def get_can_lock(self, obj) -> bool:
Expand All @@ -599,9 +605,6 @@ def get_can_lock(self, obj) -> bool:
return True
return False

def get_completed(self, obj) -> int:
return len(obj.reviews)


###################################################
# ReviewRequests - write #
Expand Down
6 changes: 6 additions & 0 deletions backend/src/zac/contrib/objects/kownsl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class KownslTypes(DjangoChoices):
approval = ChoiceItem("approval", _("Approval"))


class KownslStatus(DjangoChoices):
approved = ChoiceItem("approved", _("Approved"))
not_approved = ChoiceItem("not_approved", _("Not approved"))
pending = ChoiceItem("pending", _("Pending"))


FORM_KEY_REVIEW_TYPE_MAPPING = {
"zac:configureAdviceRequest": KownslTypes.advice,
"zac:configureApprovalRequest": KownslTypes.approval,
Expand Down
18 changes: 13 additions & 5 deletions backend/src/zac/contrib/objects/kownsl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

from djchoices import ChoiceItem, DjangoChoices
from furl import furl
from zgw_consumers.api_models.base import Model, factory
from zgw_consumers.api_models.zaken import ZaakEigenschap
Expand All @@ -21,10 +20,7 @@
from zac.elasticsearch.searches import search_informatieobjects
from zgw.models.zrc import Zaak


class KownslTypes(DjangoChoices):
advice = ChoiceItem("advice", _("Advice"))
approval = ChoiceItem("approval", _("Approval"))
from .constants import KownslStatus, KownslTypes


@dataclass
Expand Down Expand Up @@ -293,6 +289,18 @@ def get_zaakeigenschappen(self) -> List[ZaakEigenschap]:
self._zaakeigenschappen = self.zaakeigenschappen
return self._zaakeigenschappen

def get_status(self) -> str:
if self.get_completed() >= self.num_assigned_users:
if self.review_type == KownslTypes.advice:
return KownslStatus.approved
else:
return (
KownslStatus.approved
if all([review.approved for review in self.get_reviews()])
else KownslStatus.not_approved
)
return KownslStatus.pending


@dataclass
class ReviewContext(Context):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def setUpTestData(cls):
"zac.contrib.objects.services.get_reviews_for_review_request",
return_value=reviews,
)
cls.get_reviews_for_zaak_patcher = patch(
"zac.contrib.objects.kownsl.api.views.get_reviews_for_zaak",
return_value=[reviews],
)
cls.get_review_request_patcher = patch(
"zac.contrib.objects.kownsl.api.views.get_review_request",
return_value=cls.review_request,
Expand Down Expand Up @@ -244,6 +248,28 @@ def test_get_zaak_review_requests_completed(self, m):
"locked": False,
"lockReason": "",
"isBeingReconfigured": False,
"status": "pending",
}
],
)

def test_get_zaak_review_requests_status(self, m):
response = self.client.get(self.endpoint_summary)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_data = response.json()
self.assertEqual(
response_data,
[
{
"id": str(self.review_request.id),
"reviewType": KownslTypes.advice,
"completed": 0,
"numAssignedUsers": 2,
"canLock": False,
"locked": False,
"lockReason": "",
"isBeingReconfigured": False,
"status": "pending",
}
],
)
Expand All @@ -268,6 +294,7 @@ def test_get_zaak_review_requests_can_lock(self, m):
"locked": False,
"lockReason": "",
"isBeingReconfigured": False,
"status": "pending",
}
],
)
Expand Down Expand Up @@ -295,6 +322,7 @@ def test_get_zaak_review_requests_is_locked(self, m):
"locked": True,
"lockReason": "just a reason",
"isBeingReconfigured": False,
"status": "pending",
}
],
)
Expand Down
1 change: 0 additions & 1 deletion backend/src/zac/core/camunda/zet_resultaat/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from zac.contrib.objects.services import (
fetch_checklist_object,
get_all_review_requests_for_zaak,
get_reviews_for_zaak,
lock_review_request,
)
from zac.core.api.serializers import ResultaatTypeSerializer
Expand Down
1 change: 1 addition & 0 deletions backend/src/zac/core/tests/test_zet_resultaat.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def test_zet_resultaat_context_serializer(self, m):
"locked": False,
"lock_reason": "",
"is_being_reconfigured": False,
"status": "pending",
}
],
)
Expand Down
3 changes: 0 additions & 3 deletions backend/src/zac/werkvoorraad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ class WorkStackReviewRequestSerializer(PolymorphicSerializer):
help_text=_("ZAAK that review request belongs to.")
)

def get_completed(self, obj) -> int:
return len(obj.reviews)


class WorkStackSummarySerializer(serializers.Serializer):
user_tasks = serializers.IntegerField()
Expand Down

0 comments on commit feb3bb0

Please sign in to comment.