Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HL-943 | Application step 2/6 - form changes #2266

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 50 additions & 14 deletions backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
AttachmentType,
BenefitType,
OrganizationType,
PaySubsidyGranted,
)
from applications.models import (
Application,
Expand Down Expand Up @@ -752,11 +753,7 @@ def _validate_co_operation_negotiations(
def _validate_pay_subsidy(
self, pay_subsidy_granted, pay_subsidy_percent, additional_pay_subsidy_percent
):
if pay_subsidy_granted and pay_subsidy_percent is None:
raise serializers.ValidationError(
{"pay_subsidy_percent": _("Pay subsidy percent required")}
)
if not pay_subsidy_granted:
if pay_subsidy_granted == PaySubsidyGranted.NOT_GRANTED:
for key in ["pay_subsidy_percent", "additional_pay_subsidy_percent"]:
if locals()[key] is not None:
raise serializers.ValidationError(
Expand Down Expand Up @@ -813,7 +810,10 @@ def _validate_non_draft_required_fields(self, data):

# if pay_subsidy_granted is selected, then the applicant needs to also select if
# it's an apprenticeship_program or not
if data["pay_subsidy_granted"]:
if data["pay_subsidy_granted"] in [
PaySubsidyGranted.GRANTED_AGED,
PaySubsidyGranted.GRANTED,
]:
required_fields.append("apprenticeship_program")

for field_name in required_fields:
Expand Down Expand Up @@ -862,7 +862,7 @@ def _validate_benefit_type(
apprenticeship_program,
pay_subsidy_granted,
):
if benefit_type == "":
if benefit_type == BenefitType.SALARY_BENEFIT or benefit_type == "":
return
if (
benefit_type
Expand All @@ -877,6 +877,36 @@ def _validate_benefit_type(
{"benefit_type": _("This benefit type can not be selected")}
)

def _validate_apprenticeship_program(
self, apprenticeship_program, pay_subsidy_granted, status
):
if status == ApplicationStatus.DRAFT:
return
if (
pay_subsidy_granted == PaySubsidyGranted.NOT_GRANTED
and apprenticeship_program is not None
):
raise serializers.ValidationError(
{
"apprenticeship_program": _(
"Apprenticeship program can not be selected if there is no granted pay subsidy"
)
}
)

if (
pay_subsidy_granted
in [PaySubsidyGranted.GRANTED_AGED, PaySubsidyGranted.GRANTED]
and apprenticeship_program is None
):
raise serializers.ValidationError(
{
"apprenticeship_program": _(
"Apprenticeship program has to be yes or no if there is a granted pay subsidy"
)
}
)

@staticmethod
def _get_available_benefit_types(
company,
Expand All @@ -888,25 +918,26 @@ def _get_available_benefit_types(
Make the logic of determining available benefit types available both for generating the list of
benefit types and validating the incoming data
"""

if (
OrganizationType.resolve_organization_type(company.company_form_code)
== OrganizationType.ASSOCIATION
and not association_has_business_activities
):
benefit_types = [BenefitType.SALARY_BENEFIT] if pay_subsidy_granted else []
benefit_types = [
BenefitType.SALARY_BENEFIT,
]
else:
if apprenticeship_program:
benefit_types = [BenefitType.EMPLOYMENT_BENEFIT]
if pay_subsidy_granted:
benefit_types.append(BenefitType.SALARY_BENEFIT)
benefit_types = [
BenefitType.EMPLOYMENT_BENEFIT,
BenefitType.SALARY_BENEFIT,
]
else:
benefit_types = [
BenefitType.COMMISSION_BENEFIT,
BenefitType.EMPLOYMENT_BENEFIT,
BenefitType.SALARY_BENEFIT,
]
if pay_subsidy_granted:
benefit_types.append(BenefitType.SALARY_BENEFIT)
return benefit_types

def _handle_breaking_changes(self, company, data):
Expand Down Expand Up @@ -1003,6 +1034,11 @@ def validate(self, data):
data.get("apprenticeship_program"),
data.get("pay_subsidy_granted"),
)
self._validate_apprenticeship_program(
data.get("apprenticeship_program"),
data.get("pay_subsidy_granted"),
data.get("status"),
)
self._validate_non_draft_required_fields(data)
return data

Expand Down
6 changes: 6 additions & 0 deletions backend/benefit/applications/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ class AhjoDecision(models.TextChoices):
class ApplicationOrigin(models.TextChoices):
HANDLER = "handler", _("Handler")
APPLICANT = "applicant", _("Applicant")


class PaySubsidyGranted(models.TextChoices):
GRANTED = "granted", _("Pay subsidy granted (default)")
GRANTED_AGED = "granted_aged", _("Pay subsidy granted (aged)")
NOT_GRANTED = "not_granted", _("No granted pay subsidy")
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.18 on 2023-09-14 12:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('applications', '0039_alter_paysubsidy_percentages'),
]

operations = [
migrations.AlterField(
model_name='application',
name='pay_subsidy_granted',
field=models.CharField(blank=True, choices=[('aged', 'aged'), ('default', 'default'), ('none', 'none')], max_length=128, null=True),
),
migrations.AlterField(
model_name='historicalapplication',
name='pay_subsidy_granted',
field=models.CharField(blank=True, choices=[('aged', 'aged'), ('default', 'default'), ('none', 'none')], max_length=128, null=True),
),
]
9 changes: 7 additions & 2 deletions backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ApplicationStep,
AttachmentType,
BenefitType,
PaySubsidyGranted,
)
from applications.exceptions import (
BatchCompletionDecisionDateError,
Expand Down Expand Up @@ -255,7 +256,9 @@ class Application(UUIDModel, TimeStampedModel, DurationMixin):
blank=True,
)

pay_subsidy_granted = models.BooleanField(null=True)
pay_subsidy_granted = models.CharField(
null=True, choices=PaySubsidyGranted.choices, max_length=128, blank=True
)

# The PaySubsidy model stores the values entered by handlers for the calculation.
# This field is filled by the applicant.
Expand Down Expand Up @@ -306,7 +309,9 @@ def get_available_benefit_types(self):
self.is_association_application()
and not self.association_has_business_activities
):
return [BenefitType.SALARY_BENEFIT]
return [
BenefitType.SALARY_BENEFIT,
]
else:
return [
BenefitType.SALARY_BENEFIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def CSV_COLUMNS(self):
),
CsvColumn("YT-neuvottelut?", "co_operation_negotiations", format_bool),
CsvColumn("YT-neuvottelut/tiedot", "co_operation_negotiations_description"),
CsvColumn("Palkkatuki myönnetty?", "pay_subsidy_granted", format_bool),
CsvColumn("Palkkatuki myönnetty?", "pay_subsidy_granted", str),
csv_default_column("Palkkatukiprosentti", "pay_subsidy_percent"),
csv_default_column(
"Toinen palkkatukiprosentti", "additional_pay_subsidy_percent"
Expand Down
11 changes: 8 additions & 3 deletions backend/benefit/applications/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import factory

from applications.enums import ApplicationStatus, ApplicationStep, BenefitType
from applications.enums import (
ApplicationStatus,
ApplicationStep,
BenefitType,
PaySubsidyGranted,
)
from applications.models import (
AhjoDecision,
Application,
Expand Down Expand Up @@ -97,12 +102,12 @@ class ApplicationFactory(factory.django.DjangoModelFactory):
co_operation_negotiations_description = factory.Maybe(
"co_operation_negotiations", factory.Faker("paragraph"), ""
)
pay_subsidy_granted = False
pay_subsidy_granted = PaySubsidyGranted.NOT_GRANTED
pay_subsidy_percent = None

additional_pay_subsidy_percent = None

apprenticeship_program = factory.Faker("boolean")
apprenticeship_program = None
archived = False
application_step = ApplicationStep.STEP_1
benefit_type = BenefitType.EMPLOYMENT_BENEFIT
Expand Down
Loading
Loading