Skip to content

Commit

Permalink
Merge pull request #2153 from City-of-Helsinki/HL-864-failing-submit
Browse files Browse the repository at this point in the history
HL-864, HL-875: Fix failing submit for handler
  • Loading branch information
sirtawast authored Jul 30, 2023
2 parents 8b1dcfd + 78a8b0b commit d640405
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 15 deletions.
3 changes: 2 additions & 1 deletion backend/benefit/applications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class ApplicationAdmin(admin.ModelAdmin):
AttachmentInline,
CalculationInline,
)
list_filter = ("status", "company")
list_filter = ("status", "application_origin", "company")
list_display = (
"id",
"status",
"application_origin",
"application_number",
"company_name",
"company_contact_person_email",
Expand Down
21 changes: 13 additions & 8 deletions backend/benefit/applications/management/commands/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from django.core.management.base import BaseCommand
from django.utils import timezone

from applications.enums import ApplicationBatchStatus, ApplicationStatus
from applications.enums import (
ApplicationBatchStatus,
ApplicationOrigin,
ApplicationStatus,
)
from applications.models import Application, ApplicationBasis, ApplicationBatch
from applications.tests.factories import (
AdditionalInformationNeededApplicationFactory,
Expand All @@ -29,13 +33,13 @@ def add_arguments(self, parser):
parser.add_argument(
"--number",
type=int,
default=10,
default=5,
help="Number of applications to create",
)

def handle(self, *args, **options):
batch_count = 6
total_created = (len(ApplicationStatus.values) + batch_count) * options[
total_created = ((len(ApplicationStatus.values) * 2) + batch_count) * options[
"number"
]
if not settings.DEBUG:
Expand Down Expand Up @@ -104,12 +108,13 @@ def _create_batch(

for factory in factories:
for _ in range(number):
random_datetime = f.past_datetime(tzinfo=pytz.UTC)
application = factory()
application.created_at = random_datetime
application.save()
for application_origin in ApplicationOrigin.values:
random_datetime = f.past_datetime(tzinfo=pytz.UTC)
application = factory(application_origin=application_origin)
application.created_at = random_datetime
application.save()

application.log_entries.all().update(created_at=random_datetime)
application.log_entries.all().update(created_at=random_datetime)

_create_batch(ApplicationBatchStatus.DRAFT, ApplicationStatus.ACCEPTED)
_create_batch(ApplicationBatchStatus.DRAFT, ApplicationStatus.REJECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_seed_applications_with_arguments(set_debug_to_true):
amount = 5
statuses = ApplicationStatus.values
batch_count = 6
total_created = (len(ApplicationStatus.values) + batch_count) * amount
total_created = ((len(ApplicationStatus.values) * 2) + batch_count) * amount
out = StringIO()
call_command("seed", number=amount, stdout=out)

Expand Down
65 changes: 65 additions & 0 deletions backend/benefit/terms/fixtures/default_terms.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,70 @@
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
},
{
"model": "terms.terms",
"pk": "c89bac1e-aa94-4d96-b622-9a86b396b687",
"fields": {
"terms_type": "handler_terms",
"effective_from": "2021-01-01",
"terms_pdf_fi": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_sv": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_en": "/var/media/please_upload_actual_pdf_manually.pdf",
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
},
{
"model": "terms.applicantconsent",
"pk": "50365185-3cd7-4fd4-b11a-1ce43e66b601",
"fields": {
"terms": "c89bac1e-aa94-4d96-b622-9a86b396b687",
"text_fi": "Hakija on hyväksynyt ehdot",
"text_sv": "translation TBD",
"text_en": "translation TBD",
"ordering": 0,
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
},
{
"model": "terms.applicantconsent",
"pk": "66fd80cc-e362-4251-9252-90998e07bb76",
"fields": {
"terms": "c89bac1e-aa94-4d96-b622-9a86b396b687",
"text_fi": "Hakija vakuuttaa, että hänen ilmoittamansa pankkitili on organisaation virallinen tili, hänellä on oikeus asioida organisaation puolesta ja organisaatiolla ei ole verovelkoja.",
"text_sv": "translation TBD",
"text_en": "translation TBD",
"ordering": 1,
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
},
{
"model": "terms.applicantconsent",
"pk": "7832d5e1-7f85-4d8d-9a66-4df18b626925",
"fields": {
"terms": "c89bac1e-aa94-4d96-b622-9a86b396b687",
"text_fi": "Työnantaja on allekirjoittanut hakemuksen",
"text_sv": "translation TBD",
"text_en": "translation TBD",
"ordering": 2,
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
},
{
"model": "terms.applicantconsent",
"pk": "f6fed789-78d8-43bb-a798-652fa0af9287",
"fields": {
"terms": "c89bac1e-aa94-4d96-b622-9a86b396b687",
"text_fi": "Työllistettävä on allekirjoittanut hakemuksen",
"text_sv": "translation TBD",
"text_en": "translation TBD",
"ordering": 3,
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
}
]
4 changes: 4 additions & 0 deletions frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
},
"backend": {
"Request failed with status code 500": "Virhe taustajärjestelmässä. Kokeile myöhemmin uudestaan."
},
"terms": {
"label": "Ehdot hyväksymättä",
"text": "Sinun tulee hyväksyä ehdot jatkaaksesi. Palaa takaisin ja hyväksy ehdot."
}
},
"applications": {
Expand Down
4 changes: 4 additions & 0 deletions frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
},
"backend": {
"Request failed with status code 500": "Virhe taustajärjestelmässä. Kokeile myöhemmin uudestaan."
},
"terms": {
"label": "Ehdot hyväksymättä",
"text": "Sinun tulee hyväksyä ehdot jatkaaksesi. Palaa takaisin ja hyväksy ehdot."
}
},
"applications": {
Expand Down
4 changes: 4 additions & 0 deletions frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
},
"backend": {
"Request failed with status code 500": "Virhe taustajärjestelmässä. Kokeile myöhemmin uudestaan."
},
"terms": {
"label": "Ehdot hyväksymättä",
"text": "Sinun tulee hyväksyä ehdot jatkaaksesi. Palaa takaisin ja hyväksy ehdot."
}
},
"applications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const useApplicationForm = (): ExtendedComponentProps => {
validateOnChange: true,
validateOnBlur: true,
enableReinitialize: true,
onSubmit: (values) => onNext(values, id, dispatchStep, activeStep),
onSubmit: (values) => onNext(values, dispatchStep, activeStep, id),
});

const { values, setFieldValue } = formik;
Expand Down
11 changes: 7 additions & 4 deletions frontend/benefit/handler/src/hooks/useFormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import useUpdateApplicationQuery from './useUpdateApplicationQuery';
interface FormActions {
onNext: (
values: Application,
applicationId: string | undefined,
dispatchStep: React.Dispatch<StepActionType>,
activeStep: number
activeStep: number,
applicationId: string | undefined
) => Promise<ApplicationData | void>;
onSubmit: (
values: Application,
Expand Down Expand Up @@ -97,6 +97,9 @@ const useFormActions = (application: Partial<Application>): FormActions => {
)
)[0];
}
if (key === 'approveTerms') {
return <p>{t('common:error.terms.text')}</p>;
}
return (
<a key={key} href={`#${key}`}>
{value}
Expand Down Expand Up @@ -226,9 +229,9 @@ const useFormActions = (application: Partial<Application>): FormActions => {

const onNext = async (
currentValues: Application,
applicationId: string | undefined,
dispatchStep: React.Dispatch<StepActionType>,
activeStep: number
activeStep: number,
applicationId: string | undefined
): Promise<ApplicationData | void> => {
const data = getData(getModifiedValues(currentValues));

Expand Down

0 comments on commit d640405

Please sign in to comment.