Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update amount_paid after talpa CB success #3636

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -253,6 +253,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 @@ -269,12 +270,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
Loading