Skip to content

Commit

Permalink
fix: do not validate pay subsidies when application status is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtawast committed Oct 30, 2023
1 parent 812a8c3 commit 25c2c2a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion backend/benefit/applications/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,6 @@ class AhjoStatus(models.TextChoices):


class ApplicationActions(models.TextChoices):
STATUS_CHANGE = "STATUS_CHANGE", _("Status change")
APPLICANT_TOGGLE_EDIT = "APPLICANT_TOGGLE_EDIT", _(
"Allow/disallow applicant's modifications"
)
11 changes: 8 additions & 3 deletions backend/benefit/calculator/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,11 @@ def _has_handling_started(self):
and new_status in self.HANDLING_STARTED_STATUSES
)

def _are_dates_required(self, action=None):
def _are_dates_required(self):
return (
self._has_handling_started()
and self._is_salary_benefit_type()
and not self._is_manual_mode()
and action != ApplicationActions.STATUS_CHANGE
)

def _is_invalid_state_aid_max(self, state_aid_max_input: Union[None, int]) -> bool:
Expand All @@ -272,7 +271,13 @@ def validate(self, data):
request = self.context.get("request")
if request is None:
return data
if self._are_dates_required(action=ApplicationActions.STATUS_CHANGE):

action = None
if "action" in request.data:
action = request.data["action"]
if self._are_dates_required() and action not in [
ApplicationActions.APPLICANT_TOGGLE_EDIT
]:
if data.get("start_date") is None:
raise serializers.ValidationError(
{"start_date": _("Start date cannot be empty")}
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,5 @@ export enum LOCAL_STORAGE_KEYS {
}

export enum APPLICATION_ACTIONS {
STATUS_CHANGE = 'STATUS_CHANGE',
APPLICANT_TOGGLE_EDIT = 'APPLICANT_TOGGLE_EDIT',
}
4 changes: 2 additions & 2 deletions frontend/benefit/handler/src/hooks/useApplicationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Application, ApplicationData } from 'benefit-shared/types/application';
import { stringToFloatValue } from 'shared/utils/string.utils';
import snakecaseKeys from 'snakecase-keys';

import useUpdateApplicationQuery from './useUpdateApplicationQuery';
import { APPLICATION_ACTIONS } from '../constants';
import useUpdateApplicationQuery from './useUpdateApplicationQuery';

type ExtendedComponentProps = {
updateStatus: (
Expand Down Expand Up @@ -53,7 +53,7 @@ const useApplicationActions = (
},
{ deep: true }
) as ApplicationData;
const action = { action: APPLICATION_ACTIONS.STATUS_CHANGE };
const action = { action: APPLICATION_ACTIONS.APPLICANT_TOGGLE_EDIT };
updateApplicationQuery.mutate({ ...currentApplicationData, ...action });
window.scrollTo(0, 0);
};
Expand Down

0 comments on commit 25c2c2a

Please sign in to comment.