From af635c04b7c2eaf0fc498d2797b13e31bf56efb4 Mon Sep 17 00:00:00 2001 From: rikuke <33894149+rikuke@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:06:37 +0200 Subject: [PATCH] fix: attachment date in add records & update reqs (#3525) --- .../applications/services/ahjo_payload.py | 23 +++++++++++++------ .../applications/tests/test_ahjo_payload.py | 20 ++++++++++++---- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/backend/benefit/applications/services/ahjo_payload.py b/backend/benefit/applications/services/ahjo_payload.py index 6eb9b95124..b562c3c7c7 100644 --- a/backend/benefit/applications/services/ahjo_payload.py +++ b/backend/benefit/applications/services/ahjo_payload.py @@ -82,23 +82,24 @@ class UpdateRecordsRecordTitle(AhjoTitle): Attributes: prefix (str): A default string ", täydennys," that is used in the title of update records. + attachment_created_at (datetime): The created_at date of the attachment that is being updated to Ahjo. Methods: __str__(): Returns the formatted string representation of the update record title. """ prefix: str = field(default=", täydennys,") + attachment_created_at: datetime = None def __str__(self): """ Returns a formatted title string for an update record, - using the application's modification date and application number. + using the created_at date of the supplied attachment and application number. Returns: str: The formatted title string. """ - modified_at = self.application.modified_at - formatted_date = modified_at.strftime("%d.%m.%Y") + formatted_date = self.attachment_created_at.strftime("%d.%m.%Y") return self.format_title_string( formatted_date, self.application.application_number ) @@ -109,17 +110,19 @@ class AddRecordsRecordTitle(AhjoTitle): """ A class for creating the title of an additional record sent after the initial open case request. - Inherits from AhjoTitle. Uses the application's creation date and application number to format the title. + Inherits from AhjoTitle. Uses the attachment's creation date and application number to format the title. The prefix is set to ", täydennys," by default. Attributes: prefix (str): A default string ", täydennys," that is used in the title of additional records. + attachment_created_at (datetime): The created_at date of the attachment that is being updated to Ahjo. Methods: __str__(): Returns the formatted string representation of the additional record title. """ prefix: str = field(default=", täydennys,") + attachment_created_at: datetime = None def __str__(self): """ @@ -129,7 +132,7 @@ def __str__(self): Returns: str: The formatted title string. """ - formatted_date = self.application.created_at.strftime("%d.%m.%Y") + formatted_date = self.attachment_created_at.strftime("%d.%m.%Y") return self.format_title_string( formatted_date, self.application.application_number ) @@ -407,9 +410,12 @@ def prepare_attachment_records_payload( attachment_list = [] for attachment in attachments: + title = AddRecordsRecordTitle( + application=application, attachment_created_at=attachment.created_at + ) attachment_list.append( _prepare_record( - record_title=f"{AddRecordsRecordTitle(application)}", + record_title=f"{title}", record_type=AhjoRecordType.ATTACHMENT, acquired=attachment.created_at.isoformat("T", "seconds"), documents=[_prepare_record_document_dict(attachment)], @@ -431,10 +437,13 @@ def prepare_update_application_payload( f"Attachment for {application.application_number} must have a ahjo_version_series_id for update." ) language = resolve_payload_language(application) + title = UpdateRecordsRecordTitle( + application=application, attachment_created_at=pdf_summary.created_at + ) return { "records": [ _prepare_record( - record_title=f"{UpdateRecordsRecordTitle(application)}", + record_title=f"{title}", record_type=AhjoRecordType.APPLICATION, acquired=pdf_summary.created_at.isoformat("T", "seconds"), documents=[_prepare_record_document_dict(pdf_summary)], diff --git a/backend/benefit/applications/tests/test_ahjo_payload.py b/backend/benefit/applications/tests/test_ahjo_payload.py index f116cc597b..8a67f8271d 100644 --- a/backend/benefit/applications/tests/test_ahjo_payload.py +++ b/backend/benefit/applications/tests/test_ahjo_payload.py @@ -67,10 +67,13 @@ def test_open_case_record_title_str(): # Test UpdateRecordsRecordTitle class def test_update_records_record_title_str(): mock_app = Mock(spec=Application) - mock_app.modified_at = datetime(2023, 2, 25) + mock_app.created_at = datetime(2023, 3, 10) + attachment_created_at = datetime(2023, 2, 25) mock_app.application_number = "67890" - update_records_title = UpdateRecordsRecordTitle(application=mock_app) + update_records_title = UpdateRecordsRecordTitle( + application=mock_app, attachment_created_at=attachment_created_at + ) result = str(update_records_title) expected = f"{AhjoRecordTitle.APPLICATION}, täydennys, 25.02.2023, 67890" assert result == expected @@ -80,9 +83,12 @@ def test_update_records_record_title_str(): def test_add_records_record_title_str(): mock_app = Mock(spec=Application) mock_app.created_at = datetime(2023, 3, 10) + attachment_created_at = datetime(2023, 3, 10) mock_app.application_number = "54321" - add_records_title = AddRecordsRecordTitle(application=mock_app) + add_records_title = AddRecordsRecordTitle( + application=mock_app, attachment_created_at=attachment_created_at + ) result = str(add_records_title) expected = f"{AhjoRecordTitle.APPLICATION}, täydennys, 10.03.2023, 54321" assert result == expected @@ -211,6 +217,8 @@ def test_prepare_record_title( and request_type == AhjoRequestType.OPEN_CASE ): got = f"{title_class(application, current=part, total=total)}" + elif title_class in [UpdateRecordsRecordTitle, AddRecordsRecordTitle]: + got = f"{title_class(application=application, attachment_created_at=application.submitted_at)}" else: got = f"{title_class(application=application)}" assert wanted_title == got @@ -387,11 +395,13 @@ def test_prepare_update_application_payload(decided_application): attachment_type=AttachmentType.PDF_SUMMARY, ahjo_version_series_id=str(uuid.uuid4()), ) - + title = UpdateRecordsRecordTitle( + application=application, attachment_created_at=fake_summary.created_at + ) want = { "records": [ { - "Title": f"{UpdateRecordsRecordTitle(application=application,)}", + "Title": f"{title}", "Type": AhjoRecordType.APPLICATION, "Acquired": application.submitted_at.isoformat(), "PublicityClass": "Salassa pidettävä",