Skip to content

Commit

Permalink
fix: various cloning issues (hl-1539) (#3577)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sirtawast authored Nov 25, 2024
1 parent b9c3fcb commit 9c4f4ea
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/benefit/applications/api/v1/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def clone_latest(self, request) -> HttpResponse:
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
],
application_origin=ApplicationOrigin.APPLICANT,
).latest("submitted_at")

except Application.DoesNotExist:
Expand Down
40 changes: 35 additions & 5 deletions backend/benefit/applications/services/clone_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
</Button>

{process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT !== 'production' &&
stepState.activeStepIndex === 0 &&
[
APPLICATION_STATUSES.ACCEPTED,
APPLICATION_STATUSES.REJECTED,
Expand All @@ -344,6 +345,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
APPLICATION_STATUSES.ACCEPTED,
APPLICATION_STATUSES.REJECTED,
].includes(application.status) &&
stepState.activeStepIndex === 0 &&
!application.archived && (
<Button
onClick={openDialog}
Expand Down

0 comments on commit 9c4f4ea

Please sign in to comment.