-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add proposed action fields and validation #2371
Add proposed action fields and validation #2371
Conversation
7749e74
to
556aefb
Compare
fd42bcb
to
e37477b
Compare
e37477b
to
77d0b87
Compare
44d6e74
to
60a0368
Compare
7340720
to
7f21b6b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, few comments.
# NOTE: Validation for type DREF Imminent | ||
if data.get("type_of_dref") == Dref.DrefType.IMMINENT: | ||
is_surge_personnel_deployed = data.get("is_surge_personnel_deployed") | ||
sub_total = data.get("sub_total") | ||
surge_deployment_cost = data.get("surge_deployment_cost") | ||
indirect_cost = data.get("indirect_cost") | ||
total = data.get("total") | ||
proposed_actions = data.get("proposed_action", []) | ||
|
||
if not proposed_actions: | ||
raise serializers.ValidationError( | ||
{"proposed_action": gettext("Proposed Action is required for type DREF Imminent")} | ||
) | ||
if not sub_total: | ||
raise serializers.ValidationError({"sub_total": gettext("Sub-total is required for Imminent DREF")}) | ||
if sub_total != self.SUB_TOTAL: | ||
raise serializers.ValidationError( | ||
{"sub_total": gettext("Sub-total should be equal to %s for Imminent DREF" % self.SUB_TOTAL)} | ||
) | ||
if is_surge_personnel_deployed and not surge_deployment_cost: | ||
raise serializers.ValidationError( | ||
{"surge_deployment_cost": gettext("Surge Deployment is required for Imminent DREF")} | ||
) | ||
if not indirect_cost: | ||
raise serializers.ValidationError({"indirect_cost": gettext("Indirect Cost is required for Imminent DREF")}) | ||
if not total: | ||
raise serializers.ValidationError({"total": gettext("Total is required for Imminent DREF")}) | ||
|
||
proposed_budget = sum(action.get("budget", 0) for action in proposed_actions) | ||
if proposed_budget != sub_total: | ||
raise serializers.ValidationError("Sub-total should be equal to proposed budget") | ||
|
||
if is_surge_personnel_deployed: | ||
if surge_deployment_cost != self.SURGE_DEPLOYMENT_COST: | ||
raise serializers.ValidationError( | ||
{ | ||
"surge_deployment_cost": gettext( | ||
"Surge Deployment Cost should be equal to %s for Surge Personnel Deployed" | ||
% self.SURGE_DEPLOYMENT_COST | ||
) | ||
} | ||
) | ||
if indirect_cost != self.INDIRECT_COST_SURGE: | ||
raise serializers.ValidationError( | ||
{ | ||
"indirect_cost": gettext( | ||
"Indirect Cost should be equal to %s for Surge Personnel Deployed" % self.INDIRECT_COST_SURGE | ||
) | ||
} | ||
) | ||
expected_total = surge_deployment_cost + indirect_cost + sub_total | ||
else: | ||
if indirect_cost != self.INDIRECT_COST_NO_SURGE: | ||
raise serializers.ValidationError( | ||
{ | ||
"indirect_cost": gettext( | ||
"Indirect Cost should be equal to %s for No Surge Personnel Deployed" | ||
% self.INDIRECT_COST_NO_SURGE | ||
) | ||
} | ||
) | ||
expected_total = indirect_cost + sub_total | ||
|
||
if expected_total != total: | ||
raise serializers.ValidationError( | ||
{"total": gettext("Total should be equal to sum of Sub-total, Surge Deployment Cost and Indirect Cost")} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets make it clear about total
variable weather it is total_cost
or something else. Same for other variable.. like expected_total
, etc, Also update the validationError after renaming the respective variable.
Addresses
Changes
Checklist
Things that should succeed before merging.
Release
If there is a version update, make sure to tag the repository with the latest version.