Skip to content

Commit

Permalink
fix: defer accepted/rejected status until the decision has been accep…
Browse files Browse the repository at this point in the history
…ted in Ahjo (#2903)
  • Loading branch information
EmiliaMakelaVincit authored Apr 2, 2024
1 parent 3ffd311 commit 09b6340
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
14 changes: 13 additions & 1 deletion backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,11 +1402,23 @@ class ApplicantApplicationStatusChoiceField(serializers.ChoiceField):
ApplicationStatus.RECEIVED: ApplicationStatus.HANDLING,
}

def to_representation(self, value):
def get_attribute(self, obj):
return obj

def to_representation(self, application):
"""
Transform the *outgoing* native value into primitive data.
"""

value = getattr(application, self.field_name)
value_shown_to_applicant = self.STATUS_OVERRIDES.get(value, value)

if (
value in [ApplicationStatus.REJECTED, ApplicationStatus.ACCEPTED]
and not application.is_accepted_in_ahjo
):
value_shown_to_applicant = ApplicationStatus.HANDLING

return super().to_representation(value_shown_to_applicant)


Expand Down
12 changes: 12 additions & 0 deletions backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ def get_log_entry_field(self, to_statuses, field_name):
else:
return None

@property
def is_accepted_in_ahjo(self):
if self.batch is not None:
return self.batch.status in [
ApplicationBatchStatus.DECIDED_ACCEPTED,
ApplicationBatchStatus.DECIDED_REJECTED,
ApplicationBatchStatus.SENT_TO_TALPA,
ApplicationBatchStatus.COMPLETED,
]
else:
return False

def __str__(self):
return "{}: {} {} {}-{}".format(
self.pk, self.company_name, self.status, self.start_date, self.end_date
Expand Down
32 changes: 29 additions & 3 deletions backend/benefit/applications/tests/test_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ def test_application_single_read_unauthorized(
),
(ApplicationStatus.RECEIVED, ApplicationStatus.HANDLING),
(ApplicationStatus.HANDLING, ApplicationStatus.HANDLING),
(ApplicationStatus.ACCEPTED, ApplicationStatus.ACCEPTED),
(ApplicationStatus.REJECTED, ApplicationStatus.REJECTED),
(ApplicationStatus.ACCEPTED, ApplicationStatus.HANDLING),
(ApplicationStatus.REJECTED, ApplicationStatus.HANDLING),
(ApplicationStatus.CANCELLED, ApplicationStatus.CANCELLED),
],
)
def test_application_single_read_as_applicant(
def test_application_single_read_without_ahjo_decision_as_applicant(
api_client, application, actual_status, visible_status
):
application.status = actual_status
Expand All @@ -388,6 +388,32 @@ def test_application_single_read_as_applicant(
assert response.data["batch"] is True


@pytest.mark.parametrize(
"actual_status, visible_status",
[
(ApplicationStatus.ACCEPTED, ApplicationStatus.ACCEPTED),
(ApplicationStatus.REJECTED, ApplicationStatus.REJECTED),
],
)
def test_application_single_read_with_ahjo_decision_as_applicant(
api_client, application, actual_status, visible_status
):
application.status = actual_status
application.batch = ApplicationBatchFactory(status=ApplicationBatchStatus.COMPLETED)
application.save()

response = api_client.get(get_detail_url(application))
assert response.status_code == 200

assert response.data["ahjo_decision"] is not None
assert response.data["application_number"] is not None
assert response.data["status"] == visible_status
assert response.data["batch"] is True
assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months(
application.start_date, application.end_date, decimal_places=2
)


@pytest.mark.parametrize(
"status, expected_result",
[
Expand Down

0 comments on commit 09b6340

Please sign in to comment.