Skip to content

Commit

Permalink
fix: update only 1st instalment after decision cb (#3637)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Dec 5, 2024
1 parent 97ab04a commit 8822819
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,15 @@ def handle_details_request_success(
for application {application.id} and batch {batch.id} from Ahjo"

def _update_instalments_as_accepted(self, application: Application):
"""
Update the first instalment status to accepted after details are received
from Ahjo.
"""
calculation = application.calculation
instalments = Instalment.objects.filter(
calculation=calculation, status=InstalmentStatus.WAITING
calculation=calculation,
status=InstalmentStatus.WAITING,
instalment_number=1,
)
if instalments.exists():
instalments.update(status=InstalmentStatus.ACCEPTED)
Expand Down
14 changes: 13 additions & 1 deletion backend/benefit/applications/tests/test_ahjo_response_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,24 @@ def test_parse_details_from_decision_response(

@pytest.mark.parametrize(
"instalments_enabled,application_status,\
expected_batch_status, expected_proposal_for_decision, expected_instalment_1_status",
expected_batch_status, expected_proposal_for_decision, expected_instalment_1_status, \
expected_instalment_2_status",
[
(
True,
ApplicationStatus.REJECTED,
ApplicationBatchStatus.DECIDED_REJECTED,
AhjoDecision.DECIDED_REJECTED,
InstalmentStatus.WAITING,
InstalmentStatus.WAITING,
),
(
True,
ApplicationStatus.ACCEPTED,
ApplicationBatchStatus.DECIDED_ACCEPTED,
AhjoDecision.DECIDED_ACCEPTED,
InstalmentStatus.ACCEPTED,
InstalmentStatus.WAITING,
),
],
)
Expand All @@ -230,6 +233,7 @@ def test_handle_details_request_success(
expected_batch_status,
expected_proposal_for_decision,
expected_instalment_1_status,
expected_instalment_2_status,
instalments_enabled,
p2p_settings,
settings,
Expand All @@ -251,6 +255,13 @@ def test_handle_details_request_success(
amount=1000.00,
amount_paid=1000.00,
)
instalment_2 = Instalment.objects.create(
calculation=calculation,
status=InstalmentStatus.WAITING,
instalment_number=1,
amount=500.00,
amount_paid=1000.00,
)

response_handler = AhjoDecisionDetailsResponseHandler()
success_text = response_handler.handle_details_request_success(
Expand All @@ -266,6 +277,7 @@ def test_handle_details_request_success(
for application {application.id} and batch {application.batch.id} from Ahjo"
)
assert instalment_1.status == expected_instalment_1_status
assert instalment_2.status == expected_instalment_2_status
assert latest_ahjo_status.status == AhjoStatusEnum.DETAILS_RECEIVED_FROM_AHJO

batch = application.batch
Expand Down

0 comments on commit 8822819

Please sign in to comment.