Skip to content

Commit

Permalink
feat: HL 1460 (#3305)
Browse files Browse the repository at this point in the history
* feat: multiple ahjo statuses in query

* feat: NEW_RECORDS_REQUEST_SENT status after req

* fix: dont query with new_records_received for now

* fix: test
  • Loading branch information
rikuke authored Sep 12, 2024
1 parent 535794e commit 1a7ca0c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_applications_for_request(
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
],
AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO,
[AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO],
True,
)
elif request_type == AhjoRequestType.SEND_DECISION_PROPOSAL:
Expand All @@ -82,13 +82,13 @@ def get_applications_for_request(
elif request_type == AhjoRequestType.UPDATE_APPLICATION:
applications = Application.objects.get_by_statuses(
[ApplicationStatus.ACCEPTED, ApplicationStatus.REJECTED],
AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
[AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED],
False,
)
elif request_type == AhjoRequestType.GET_DECISION_DETAILS:
applications = Application.objects.get_by_statuses(
[ApplicationStatus.ACCEPTED, ApplicationStatus.REJECTED],
AhjoStatusEnum.SIGNED_IN_AHJO,
[AhjoStatusEnum.SIGNED_IN_AHJO],
False,
)
elif request_type == AhjoRequestType.DELETE_APPLICATION:
Expand Down
9 changes: 7 additions & 2 deletions backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,17 @@ def with_non_downloaded_attachments(self):
def get_by_statuses(
self,
application_statuses: List[ApplicationStatus],
ahjo_status: AhjoStatusEnum,
ahjo_statuses: List[AhjoStatusEnum],
has_no_case_id: bool,
):
"""
Query applications by their latest AhjoStatus relation
and their current ApplicationStatus and if they have a case id in Ahjo or not.
The latest ahjo status can be one of several as for example in the case of update
records request, where the previous status can be either:
AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
or
AhjoStatusEnum.NEW_RECORDS_RECEIVED
"""
# Subquery to get the latest AhjoStatus id for each application
latest_ahjo_status_subquery = (
Expand Down Expand Up @@ -204,7 +209,7 @@ def get_by_statuses(
.filter(
status__in=application_statuses,
ahjo_status__id=F("latest_ahjo_status_id"),
ahjo_status__status=ahjo_status,
ahjo_status__status__in=ahjo_statuses,
ahjo_case_id__isnull=has_no_case_id,
)
.prefetch_related(attachments_prefetch, "calculation", "company")
Expand Down
1 change: 1 addition & 0 deletions backend/benefit/applications/services/ahjo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AhjoAddRecordsRequest(AhjoRequest):

request_type = AhjoRequestType.ADD_RECORDS
request_method = "POST"
result_status = AhjoStatusEnum.NEW_RECORDS_REQUEST_SENT


@dataclass
Expand Down
6 changes: 4 additions & 2 deletions backend/benefit/applications/services/ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,11 @@ def send_new_attachment_records_to_ahjo(

data = prepare_attachment_records_payload(attachments, application)

application, response_text = ahjo_client.send_request_to_ahjo(data)
result, response_text = ahjo_client.send_request_to_ahjo(data)

return application, response_text
if result:
create_status_for_application(application, ahjo_request.result_status)
return result, response_text


def send_decision_proposal_to_ahjo(
Expand Down
2 changes: 1 addition & 1 deletion backend/benefit/applications/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def multiple_applications_with_ahjo_case_id(
):
with factory.Faker.override_default_locale("fi_FI"):
applications = DecidedApplicationFactory.create_batch(
5, company=mock_get_organisation_roles_and_create_company
10, company=mock_get_organisation_roles_and_create_company
)

for a in applications:
Expand Down
14 changes: 11 additions & 3 deletions backend/benefit/applications/tests/test_ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,26 @@ def test_generate_ahjo_secret_decision_text_xml(decided_application):
def test_get_applications_for_ahjo_update(
multiple_applications_with_ahjo_case_id,
):
for a in multiple_applications_with_ahjo_case_id:
for a in multiple_applications_with_ahjo_case_id[:5]:
AhjoStatus.objects.create(
application=a,
status=AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
)
for a in multiple_applications_with_ahjo_case_id[5:]:
AhjoStatus.objects.create(
application=a,
status=AhjoStatusEnum.NEW_RECORDS_RECEIVED,
)

applications_for_ahjo_update = Application.objects.get_by_statuses(
[
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
],
AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
[
AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
AhjoStatusEnum.NEW_RECORDS_RECEIVED,
],
False,
)

Expand Down Expand Up @@ -844,7 +852,7 @@ def test_get_applications_for_open_case(
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
],
AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO,
[AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO],
True,
)

Expand Down

0 comments on commit 1a7ca0c

Please sign in to comment.