Skip to content

Commit

Permalink
feat: ensure ahjo_status is saved during request (#3380)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Oct 4, 2024
1 parent 348aa31 commit f2e9c37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 8 additions & 1 deletion backend/benefit/applications/services/ahjo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.urls import reverse

from applications.enums import AhjoRequestType, AhjoStatus as AhjoStatusEnum
from applications.models import AhjoSetting, Application
from applications.models import AhjoSetting, AhjoStatus, Application
from applications.services.ahjo_authentication import AhjoToken, InvalidTokenException

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -235,6 +235,13 @@ def send_request_to_ahjo(
timeout=self._timeout,
data=data,
)

if hasattr(self._request, "result_status") and self._request.result_status:
AhjoStatus.objects.create(
application=self._request.application,
status=self._request.result_status,
)

response.raise_for_status()

if response.ok:
Expand Down
12 changes: 1 addition & 11 deletions backend/benefit/applications/services/ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ def send_open_case_request_to_ahjo(
data = prepare_open_case_payload(application, pdf_summary)

result, response_text = ahjo_client.send_request_to_ahjo(data)
if result:
create_status_for_application(
application, AhjoStatusEnum.REQUEST_TO_OPEN_CASE_SENT
)
return result, response_text


Expand All @@ -504,8 +500,7 @@ def delete_application_in_ahjo(
ahjo_client = AhjoApiClient(ahjo_token, ahjo_request)

result, response_text = ahjo_client.send_request_to_ahjo(None)
if result:
create_status_for_application(application, ahjo_request.result_status)

return result, response_text


Expand All @@ -532,8 +527,6 @@ def update_application_summary_record_in_ahjo(

result, response_text = ahjo_client.send_request_to_ahjo(data)

if result:
create_status_for_application(application, AhjoStatusEnum.UPDATE_REQUEST_SENT)
return result, response_text


Expand All @@ -554,8 +547,6 @@ def send_new_attachment_records_to_ahjo(

result, response_text = ahjo_client.send_request_to_ahjo(data)

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


Expand Down Expand Up @@ -584,7 +575,6 @@ def send_decision_proposal_to_ahjo(
secret_xml=secret_xml,
)
response, response_text = ahjo_client.send_request_to_ahjo(data)
create_status_for_application(application, AhjoStatusEnum.DECISION_PROPOSAL_SENT)
return response, response_text


Expand Down

0 comments on commit f2e9c37

Please sign in to comment.