Skip to content

Commit

Permalink
fix: record title for add records request (#3320)
Browse files Browse the repository at this point in the history
* fix: record title for add records request

* fix: serializer linting

* fix: test linting
  • Loading branch information
rikuke authored Sep 12, 2024
1 parent ac1a6df commit 8c119f4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
12 changes: 6 additions & 6 deletions backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
36 changes: 23 additions & 13 deletions backend/benefit/applications/services/ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}"


Expand Down
40 changes: 35 additions & 5 deletions backend/benefit/applications/tests/test_ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 8c119f4

Please sign in to comment.