Skip to content

Commit

Permalink
feat: implement instalments gui for handler (hl-1494) (#3498)
Browse files Browse the repository at this point in the history
* refactor: extract manual ahjo index to it's own component

* feat: implement api endpoints for instalments

* chore: update translations

* feat: implement instalment ui

* test: add fixtures for instalment e2e tests
  • Loading branch information
sirtawast authored Nov 6, 2024
1 parent 0b49eb3 commit aaff375
Show file tree
Hide file tree
Showing 24 changed files with 1,253 additions and 214 deletions.
Empty file.
24 changes: 24 additions & 0 deletions backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@
from calculator.api.v1.serializers import (
CalculationSearchSerializer,
CalculationSerializer,
InstalmentSerializer,
PaySubsidySerializer,
TrainingCompensationSerializer,
)
from calculator.enums import InstalmentStatus
from calculator.models import Calculation
from common.delay_call import call_now_or_later, do_delayed_calls_at_end
from common.exceptions import BenefitAPIException
Expand Down Expand Up @@ -1903,6 +1905,7 @@ class Meta:
"batch",
"ahjo_error",
"talpa_status",
"pending_instalment",
]

read_only_fields = [
Expand All @@ -1927,6 +1930,7 @@ class Meta:
"batch",
"ahjo_error",
"talpa_status",
"pending_instalment",
]

archived = serializers.BooleanField()
Expand All @@ -1947,6 +1951,26 @@ class Meta:
"Timestamp when the application was handled (accepted/rejected/cancelled)"
),
)
pending_instalment = serializers.SerializerMethodField("get_pending_instalment")

def get_pending_instalment(self, application):
"""Get the latest pending instalment for the application"""
try:
instalments = application.calculation.instalments.filter(
instalment_number__gt=1
)
instalment = (
instalments.exclude(status=InstalmentStatus.COMPLETED)
.order_by("-due_date")
.first()
or None
)
if instalment is not None:
return InstalmentSerializer(instalment).data
except AttributeError:
return None
return None

ahjo_error = serializers.SerializerMethodField("get_latest_ahjo_error")

def get_latest_ahjo_error(self, obj) -> Union[Dict, None]:
Expand Down
Loading

0 comments on commit aaff375

Please sign in to comment.