-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement new Ahjo process UI for handler (HL-1167)
* feat(backend): list start and end dates for calculation sum rows * feat(backend): add calc row description type to expose in api * feat(backend): add decision proposal draft model and api * test(backend): write tests for decision proposal drafting * chore(backend): rewrite template sections - decision and justification to same object * feat(shared): extend Heading component to include font-weight * feat(shared): extend Heading to take in `css` attributes via `$css` * feat(shared): sidebar can be set a bit shorter if sticky bar is used * fix(prep): remove HTML semicolon, use coatOfArms styling * fix(prep): application review values font-size according to layout * fix(prep): tweak approval / rejection radio button group styles * chore(prep): extend stepper component styles to cover both coat and black * feat(prep): add setting to toggle new ahjo mode on/off * test(frontend): application approval and old batch process * feat(frontend): add a stepper to application review * feat(frontend): use review stepper and split application review to pages * chore(frontend): add translation for application reviews * fix(frontend): use extended version of horizontal list for batches * fix: rename migrate files as they were in conflict with #2890 * refactor: migrations from hl-1167 * feat(backend): add decision proposal draft model and api * chore(backend): rewrite template sections - decision and justification to same object * chore(backend): add application test fixture * test(backend): add decision template fixture * feat(backend): use language parameter to filter template sections * feat(backend): write log entry if decision is of type denied * fix(backend): denied decision might not have calculation * fix(backend): tighter validation for decision texts * feat(shared): allow P type for Heading * test(frontend): extract upload function to utils * feat(handler): add ahjo decision template editor * refactor(handler): generalise params to show different kind of notifications * chore: cleanup review step2 and extract calculation table to component * refactor(frontend): clean up validation rules for disabling next button * feat(handler): stepper subheading on third index * feat(handler): add loading skeleton css for neat loading animations * test(frontend): extract shared function to utility * fix(frontend): more loading skeletons * refactor(frontend): relocate awaiting for new data ribbon, move ahjo beta button location * feat(frontend): show submission successful notification for new ahjo process * test(frontend): write ahjo process tests * fix: ease on conditions to show handling bar * chore(frontend): add translation files * fix: resolve migrations with rebase * fix: resolve some PR review issues * refactor: typo in filename * fix: add line break so that header values will fit in one row * refactor: move handling views and hooks to own dirs * test: resolve issues with @rikuke's new Ahjo work * fix: remove some css props, use variables * fix: do not log CLAMAV nag on dev environment * test(fix): issue with localStorage * fix: add handling bar for sent application but hide button
- Loading branch information
Showing
92 changed files
with
4,087 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
backend/benefit/applications/api/v1/decision_proposal_draft_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
from django.db import transaction | ||
from django.shortcuts import get_object_or_404 | ||
from django_filters import rest_framework as filters | ||
from drf_spectacular.utils import extend_schema | ||
from rest_framework import filters as drf_filters, status, viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.response import Response | ||
|
||
from applications.api.v1.serializers.decision_proposal import ( | ||
AhjoDecisionProposalReadOnlySerializer, | ||
AhjoDecisionProposalSerializer, | ||
) | ||
from applications.enums import ApplicationStatus, DecisionType | ||
from applications.models import AhjoDecisionProposalDraft, AhjoDecisionText, Application | ||
from common.permissions import BFIsHandler | ||
|
||
|
||
class AhjoDecisionProposalDraftFilter(filters.FilterSet): | ||
class Meta: | ||
model = AhjoDecisionProposalDraft | ||
fields = { | ||
"status": ["exact"], | ||
} | ||
|
||
|
||
@extend_schema( | ||
description=( | ||
"API for create/read/update/delete/export operations on Helsinki benefit" | ||
" application batches" | ||
) | ||
) | ||
class AhjoDecisionProposalDraftViewSet(viewsets.ViewSet): | ||
queryset = AhjoDecisionProposalDraft.objects.all() | ||
serializer_class = AhjoDecisionProposalSerializer | ||
permission_classes = [BFIsHandler] | ||
filter_backends = [ | ||
drf_filters.OrderingFilter, | ||
filters.DjangoFilterBackend, | ||
drf_filters.SearchFilter, | ||
] | ||
filterset_class = AhjoDecisionProposalDraftFilter | ||
|
||
def get_queryset(self): | ||
order_by = self.request.query_params.get("order_by") or None | ||
|
||
if order_by: | ||
self.queryset = self.queryset.order_by(order_by) | ||
|
||
return self.queryset | ||
|
||
def get_serializer_class(self): | ||
""" | ||
ApplicationBatchSerializer for default behaviour on mutation functions, | ||
ApplicationBatchListSerializer for listing applications on a batch | ||
""" | ||
if self.action in ["create", "update", "partial_update", "destroy"]: | ||
return AhjoDecisionProposalReadOnlySerializer | ||
|
||
return AhjoDecisionProposalSerializer | ||
|
||
@action(methods=["PATCH"], detail=False) | ||
@transaction.atomic | ||
def modify(self, request, pk=None): | ||
""" | ||
Override default destroy(), batch can only be deleted if it's status is "draft" | ||
""" | ||
app_id = request.data["application_id"] | ||
application = get_object_or_404(Application, id=app_id) | ||
|
||
proposal_object = AhjoDecisionProposalDraft.objects.filter( | ||
application=application | ||
).first() | ||
|
||
proposal = AhjoDecisionProposalSerializer( | ||
proposal_object, data=request.data, partial=True | ||
) | ||
|
||
if not proposal.is_valid(): | ||
return Response(proposal.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
data = proposal.validated_data | ||
proposal.save() | ||
|
||
if data.get("decision_text") and data.get("justification_text"): | ||
ahjo_text = AhjoDecisionText.objects.filter(application=application) | ||
if ahjo_text: | ||
ahjo_text.update( | ||
language=application.applicant_language, | ||
decision_type=( | ||
DecisionType.ACCEPTED | ||
if data["status"] == ApplicationStatus.ACCEPTED | ||
else DecisionType.DENIED | ||
), | ||
decision_text=data["decision_text"] | ||
+ "\n\n" | ||
+ data["justification_text"], | ||
) | ||
else: | ||
AhjoDecisionText.objects.create( | ||
application=application, | ||
language=application.applicant_language, | ||
decision_type=( | ||
DecisionType.ACCEPTED | ||
if data["status"] == ApplicationStatus.ACCEPTED | ||
else DecisionType.DENIED | ||
), | ||
decision_text=data["decision_text"] | ||
+ "\n\n" | ||
+ data["justification_text"], | ||
) | ||
|
||
if data["review_step"] >= 4: | ||
# Ensure GUI has a page that exists | ||
proposal.review_step = 3 | ||
proposal.save() | ||
|
||
application.status = data["status"] | ||
application.save() | ||
|
||
application.calculation.granted_as_de_minimis_aid = data[ | ||
"granted_as_de_minimis_aid" | ||
] | ||
application.calculation.save() | ||
|
||
return Response(proposal.data, status=status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.