Skip to content

Commit

Permalink
fix: reset a few values when apprenticeship or pay subsidy type is ch…
Browse files Browse the repository at this point in the history
…anged (#3218)
  • Loading branch information
sirtawast authored Aug 22, 2024
1 parent 94ba9e9 commit bed8592
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1291,18 +1291,23 @@ def _base_update(self, instance, validated_data):
employee_data = validated_data.pop("employee", None)
approve_terms = validated_data.pop("approve_terms", None)
decision_proposal_data = validated_data.pop("decision_proposal", None)
apprenticeship_program = validated_data.get("apprenticeship_program", None)
pre_update_status = instance.status
application = super().update(instance, validated_data)

if de_minimis_data is not None:
# if it is a patch request that didn't have de_minimis_data_set, do nothing
self._update_de_minimis_aid(application, de_minimis_data)
if employee_data is not None:
self._update_or_create_employee(application, employee_data)

if decision_proposal_data is not None:
AhjoDecisionProposalDraft.objects.update_or_create(
application=application, defaults=decision_proposal_data
)
if apprenticeship_program is None or apprenticeship_program is False:
application.training_compensations.all().delete()
if application.pay_subsidy_granted == PaySubsidyGranted.NOT_GRANTED:
application.pay_subsidies.all().delete()

if instance.status != pre_update_status:
self.handle_status_transition(
Expand Down
5 changes: 4 additions & 1 deletion frontend/benefit/applicant/src/hooks/useFormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ const useFormActions = (application: Partial<Application>): FormActions => {
endDate: endDate
? convertToBackendDateFormat(parseDate(endDate))
: undefined,
apprenticeshipProgram,
apprenticeshipProgram:
paySubsidyGranted !== PAY_SUBSIDY_GRANTED.NOT_GRANTED
? apprenticeshipProgram
: null,
};

// Use context on first step, otherwise pass data from backend
Expand Down
3 changes: 1 addition & 2 deletions frontend/benefit/handler/src/hooks/useFormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ const useFormActions = (
values: Partial<Application>
): TrainingCompensation[] => {
if (
values.apprenticeshipProgram ===
initialApplication?.apprenticeshipProgram &&
values.apprenticeshipProgram &&
values.paySubsidyGranted !== PAY_SUBSIDY_GRANTED.NOT_GRANTED
) {
// Return the training compensation values as they are
Expand Down

0 comments on commit bed8592

Please sign in to comment.