Skip to content

Commit

Permalink
feat: update amount_paid after talpa CB success (#3636)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Dec 5, 2024
1 parent f9bbaf9 commit 97ab04a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
25 changes: 19 additions & 6 deletions backend/benefit/applications/api/v1/talpa_integration_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import transaction
from django.utils import timezone
from rest_framework import status
Expand Down Expand Up @@ -170,12 +171,24 @@ def do_status_updates_based_on_instalments(
Always set the application as archived after the first instalment is succesfully sent to talpa.
"""
for application in applications:
instalment = application.calculation.instalments.get(
status=InstalmentStatus.ACCEPTED,
due_date__lte=timezone.now().date(),
)
instalment.status = instalment_status
instalment.save()
try:
instalment = application.calculation.instalments.get(
status=InstalmentStatus.ACCEPTED,
due_date__lte=timezone.now().date(),
)
instalment.status = instalment_status
if is_success:
instalment.amount_paid = instalment.amount_after_recoveries
instalment.save()
except ObjectDoesNotExist:
LOGGER.error(
f"Valid payable Instalment not found for application {application.application_number}"
)
except MultipleObjectsReturned:
LOGGER.error(
f"Multiple payable Instalments found for application \
{application.application_number}, there should be only one"
)

if is_success:
# after 1st instalment is sent to talpa,
Expand Down
3 changes: 3 additions & 0 deletions backend/benefit/applications/tests/test_talpa_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def test_talpa_callback_success(

for instalment in instalments:
assert instalment.status == InstalmentStatus.PAID
assert instalment.amount_paid == instalment.amount_after_recoveries

if number_of_instalments == 1:
assert (
Expand All @@ -314,12 +315,14 @@ def test_talpa_callback_success(
instalment_1 = decided_application.calculation.instalments.get(
instalment_number=1
)
assert instalment_1.amount_paid == instalment.amount_after_recoveries
assert instalment_1.status == InstalmentStatus.PAID

instalment_2 = decided_application.calculation.instalments.get(
instalment_number=2
)
assert instalment_2.status == InstalmentStatus.WAITING
assert instalment_2.amount_paid is None

assert (
decided_application.talpa_status
Expand Down

0 comments on commit 97ab04a

Please sign in to comment.