From 8c119f4d4eb91fc174a664923762bad44a8cbd0f Mon Sep 17 00:00:00 2001 From: rikuke <33894149+rikuke@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:38:19 +0300 Subject: [PATCH] fix: record title for add records request (#3320) * fix: record title for add records request * fix: serializer linting * fix: test linting --- .../api/v1/serializers/application.py | 12 +++--- .../applications/services/ahjo_payload.py | 36 +++++++++++------ .../applications/tests/test_ahjo_payload.py | 40 ++++++++++++++++--- 3 files changed, 64 insertions(+), 24 deletions(-) diff --git a/backend/benefit/applications/api/v1/serializers/application.py b/backend/benefit/applications/api/v1/serializers/application.py index 5a8b4669c8..21d1e05574 100755 --- a/backend/benefit/applications/api/v1/serializers/application.py +++ b/backend/benefit/applications/api/v1/serializers/application.py @@ -1398,9 +1398,9 @@ def _update_de_minimis_aid(self, application, de_minimis_data): for idx, aid_item in enumerate(serializer.validated_data): aid_item["application_id"] = application.pk - aid_item["ordering"] = ( - idx # use the ordering defined in the JSON sent by the client - ) + aid_item[ + "ordering" + ] = idx # use the ordering defined in the JSON sent by the client de_minimis_list = serializer.save() for de_minimis in de_minimis_list: @@ -1809,9 +1809,9 @@ def _common_ordered_nested_update(self, application, serializer): ) for idx, nested_object in enumerate(serializer.validated_data): nested_object["application_id"] = application.pk - nested_object["ordering"] = ( - idx # use the ordering defined in the JSON sent by the client - ) + nested_object[ + "ordering" + ] = idx # use the ordering defined in the JSON sent by the client serializer.save() if hasattr(application, "calculation"): call_now_or_later( diff --git a/backend/benefit/applications/services/ahjo_payload.py b/backend/benefit/applications/services/ahjo_payload.py index fffeb3e4e3..ed5b6051c7 100644 --- a/backend/benefit/applications/services/ahjo_payload.py +++ b/backend/benefit/applications/services/ahjo_payload.py @@ -20,7 +20,6 @@ from users.models import User MANNER_OF_RECEIPT = "sähköinen asiointi" -IS_UPDATE_TITLE_PART = " täydennys," def _prepare_record_title( @@ -30,21 +29,32 @@ def _prepare_record_title( current: int = 0, total: int = 0, ) -> str: - """Prepare the title for the application record in Ahjo in the format: - Hakemus 11.4.2024, 128123 - or for an attachment: - Hakemus 11.4.2024, liite 1/3, 128123 - If the request type is an update, add the word "täydennys" to the title. + """Prepare the title for the application record in Ahjo in the required format: + If the request type is an update or adding new records, add the word "täydennys" to the title. + For example: + for open case: + Hakemus 22.8.2024, 125xxx + for adding new records: + Hakemus, täydennys (päivämäärä jolloin täydennys saapunut), 125xxx + and for attachments in the open case request: + Hakemus 26.3.2024, liite 1/1, 123xxx """ formatted_date = application.created_at.strftime("%d.%m.%Y") - title_part = ( - IS_UPDATE_TITLE_PART - if request_type == AhjoRequestType.UPDATE_APPLICATION - else "" - ) - if record_type == AhjoRecordType.APPLICATION: - return f"{AhjoRecordTitle.APPLICATION},{title_part} {formatted_date}, {application.application_number}" + if ( + request_type == AhjoRequestType.OPEN_CASE + and record_type == AhjoRecordType.APPLICATION + ): + return f"{AhjoRecordTitle.APPLICATION} {formatted_date}, {application.application_number}" + elif ( + request_type == AhjoRequestType.UPDATE_APPLICATION + and record_type == AhjoRecordType.APPLICATION + ) or ( + request_type == AhjoRequestType.ADD_RECORDS + and record_type == AhjoRecordType.ATTACHMENT + ): + return f"{AhjoRecordTitle.APPLICATION}, täydennys {formatted_date}, {application.application_number}" + return f"{AhjoRecordTitle.APPLICATION} {formatted_date}, liite {current}/{total}, {application.application_number}" diff --git a/backend/benefit/applications/tests/test_ahjo_payload.py b/backend/benefit/applications/tests/test_ahjo_payload.py index 9de3b85c19..0d76c4e5a0 100644 --- a/backend/benefit/applications/tests/test_ahjo_payload.py +++ b/backend/benefit/applications/tests/test_ahjo_payload.py @@ -73,30 +73,60 @@ def test_prepare_final_case_title_truncate( @pytest.mark.parametrize( - "record_title, record_type, request_type, wanted_title_addition", + "record_title, record_type, request_type, wanted_title_addition, part, total", [ ( AhjoRecordTitle.APPLICATION, AhjoRecordType.APPLICATION, AhjoRequestType.OPEN_CASE, "", + 0, + 0, ), ( AhjoRecordTitle.APPLICATION, AhjoRecordType.APPLICATION, AhjoRequestType.UPDATE_APPLICATION, - " täydennys,", + ", täydennys", + 0, + 0, + ), + ( + AhjoRecordTitle.APPLICATION, + AhjoRecordType.ATTACHMENT, + AhjoRequestType.ADD_RECORDS, + ", täydennys", + 0, + 0, + ), + ( + AhjoRecordTitle.APPLICATION, + AhjoRecordType.ATTACHMENT, + AhjoRequestType.OPEN_CASE, + "", + 1, + 3, ), ], ) def test_prepare_record_title( - decided_application, record_title, record_type, request_type, wanted_title_addition + decided_application, + record_title, + record_type, + request_type, + wanted_title_addition, + part, + total, ): application = decided_application formatted_date = application.created_at.strftime("%d.%m.%Y") - wanted_title = f"{record_title},{wanted_title_addition} {formatted_date}, {application.application_number}" - got = _prepare_record_title(application, record_type, request_type) + if part and total: + wanted_title = f"{record_title}{wanted_title_addition} {formatted_date},\ + liite {part}/{total}, {application.application_number}" + else: + wanted_title = f"{record_title}{wanted_title_addition} {formatted_date}, {application.application_number}" + got = _prepare_record_title(application, record_type, request_type, part, total) assert wanted_title == got