From 9c4f4ea7306cabf10503046c8393e349ab7b1f38 Mon Sep 17 00:00:00 2001 From: Sampo Tawast <5328394+sirtawast@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:12:52 +0200 Subject: [PATCH] fix: various cloning issues (hl-1539) (#3577) * fix: ensure cloned application is of origin type "applicant" * fix: set test values if no company address value exist * fix: clone only specific attachments * fix: add missing ahjo status when cloning * fix: hide cancel and clone buttons on decision steps --- .../applications/api/v1/application_views.py | 1 + .../services/clone_application.py | 40 ++++++++++++++++--- .../handler/public/locales/en/common.json | 2 +- .../handler/public/locales/fi/common.json | 2 +- .../handler/public/locales/sv/common.json | 2 +- .../HandlingApplicationActionsAhjo.tsx | 2 + 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/backend/benefit/applications/api/v1/application_views.py b/backend/benefit/applications/api/v1/application_views.py index 769e09f302..446d52a423 100755 --- a/backend/benefit/applications/api/v1/application_views.py +++ b/backend/benefit/applications/api/v1/application_views.py @@ -676,6 +676,7 @@ def clone_latest(self, request) -> HttpResponse: ApplicationStatus.ACCEPTED, ApplicationStatus.REJECTED, ], + application_origin=ApplicationOrigin.APPLICANT, ).latest("submitted_at") except Application.DoesNotExist: diff --git a/backend/benefit/applications/services/clone_application.py b/backend/benefit/applications/services/clone_application.py index ae464c6750..9bd5477de7 100644 --- a/backend/benefit/applications/services/clone_application.py +++ b/backend/benefit/applications/services/clone_application.py @@ -3,8 +3,14 @@ from django.core.files.uploadedfile import InMemoryUploadedFile from PIL import Image -from applications.enums import ApplicationStatus, ApplicationStep +from applications.enums import ( + AhjoStatus as AhjoStatusEnum, + ApplicationStatus, + ApplicationStep, + AttachmentType, +) from applications.models import ( + AhjoStatus, Application, ApplicationLogEntry, Attachment, @@ -20,9 +26,16 @@ def clone_application_based_on_other( clone_all_data=False, ): company = Company.objects.get(id=application_base.company.id) - company.street_address = ( - company.street_address if len(company.street_address) > 0 else "Testikatu 123" - ) + if clone_all_data: + company.street_address = ( + company.street_address + if len(company.street_address) > 0 + else "Testikatu 123" + ) + + company.postcode = company.postcode if len(company.postcode) > 0 else "00100" + company.city = company.city if len(company.city) > 0 else "Testilä" + cloned_application = Application( **{ "alternative_company_city": application_base.alternative_company_city, @@ -129,7 +142,19 @@ def _clone_handler_data(application_base, cloned_application): ) # Mimick the attachments by retaining attachment type - for base_attachment in application_base.attachments.all(): + for base_attachment in application_base.attachments.filter( + attachment_type__in=[ + AttachmentType.EMPLOYMENT_CONTRACT, + AttachmentType.PAY_SUBSIDY_DECISION, + AttachmentType.COMMISSION_CONTRACT, + AttachmentType.EDUCATION_CONTRACT, + AttachmentType.HELSINKI_BENEFIT_VOUCHER, + AttachmentType.EMPLOYEE_CONSENT, + AttachmentType.FULL_APPLICATION, + AttachmentType.OTHER_ATTACHMENT, + AttachmentType.PDF_SUMMARY, + ] + ): Attachment.objects.create( attachment_type=base_attachment.attachment_type, application=cloned_application, @@ -142,6 +167,11 @@ def _clone_handler_data(application_base, cloned_application): cloned_application.end_date = application_base.end_date cloned_application.save() + AhjoStatus.objects.create( + status=AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO, + application=cloned_application, + ) + calculation_base = application_base.calculation Calculation.objects.create_for_application( cloned_application, diff --git a/frontend/benefit/handler/public/locales/en/common.json b/frontend/benefit/handler/public/locales/en/common.json index 8a8f1f3e82..5d543e7feb 100644 --- a/frontend/benefit/handler/public/locales/en/common.json +++ b/frontend/benefit/handler/public/locales/en/common.json @@ -1041,7 +1041,7 @@ "handlingPanel": "Käsittelypaneeli", "search": "Hae arkistosta", "cancel": "Peruuta hakemus", - "clone": "Kloonaa hakemus", + "clone": "Kopioi hakemus", "addAttachment": "Liitä uusi tiedosto", "addPreviouslyGrantedBenefit": "Lisää aikaisempi lisä", "targetGroupCheck": "Kohderyhmätarkistus", diff --git a/frontend/benefit/handler/public/locales/fi/common.json b/frontend/benefit/handler/public/locales/fi/common.json index 14d0e82466..bd5534459c 100644 --- a/frontend/benefit/handler/public/locales/fi/common.json +++ b/frontend/benefit/handler/public/locales/fi/common.json @@ -1041,7 +1041,7 @@ "handlingPanel": "Käsittelypaneeli", "search": "Hae arkistosta", "cancel": "Peruuta hakemus", - "clone": "Kloonaa hakemus", + "clone": "Kopioi hakemus", "addAttachment": "Liitä uusi tiedosto", "addPreviouslyGrantedBenefit": "Lisää aikaisempi lisä", "targetGroupCheck": "Kohderyhmätarkistus", diff --git a/frontend/benefit/handler/public/locales/sv/common.json b/frontend/benefit/handler/public/locales/sv/common.json index c4bbf464e1..bcd99a5106 100644 --- a/frontend/benefit/handler/public/locales/sv/common.json +++ b/frontend/benefit/handler/public/locales/sv/common.json @@ -1041,7 +1041,7 @@ "handlingPanel": "Käsittelypaneeli", "search": "Hae arkistosta", "cancel": "Peruuta hakemus", - "clone": "Kloonaa hakemus", + "clone": "Kopioi hakemus", "addAttachment": "Liitä uusi tiedosto", "addPreviouslyGrantedBenefit": "Lisää aikaisempi lisä", "targetGroupCheck": "Kohderyhmätarkistus", diff --git a/frontend/benefit/handler/src/components/applicationReview/actions/handlingApplicationActions/HandlingApplicationActionsAhjo.tsx b/frontend/benefit/handler/src/components/applicationReview/actions/handlingApplicationActions/HandlingApplicationActionsAhjo.tsx index f4a452b430..58a47fcf19 100644 --- a/frontend/benefit/handler/src/components/applicationReview/actions/handlingApplicationActions/HandlingApplicationActionsAhjo.tsx +++ b/frontend/benefit/handler/src/components/applicationReview/actions/handlingApplicationActions/HandlingApplicationActionsAhjo.tsx @@ -323,6 +323,7 @@ const HandlingApplicationActions: React.FC = ({ {process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT !== 'production' && + stepState.activeStepIndex === 0 && [ APPLICATION_STATUSES.ACCEPTED, APPLICATION_STATUSES.REJECTED, @@ -344,6 +345,7 @@ const HandlingApplicationActions: React.FC = ({ APPLICATION_STATUSES.ACCEPTED, APPLICATION_STATUSES.REJECTED, ].includes(application.status) && + stepState.activeStepIndex === 0 && !application.archived && (