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

Add proposed action fields and validation #2371

Conversation

sudan45
Copy link

@sudan45 sudan45 commented Jan 3, 2025

Addresses

Changes

  • Add new model proposed actions
  • remove field from serializer for dref imminent
  • Update proposed action request and response in api and update validation

Checklist

Things that should succeed before merging.

  • Updated/ran unit tests
  • Updated CHANGELOG.md

Release

If there is a version update, make sure to tag the repository with the latest version.

@sudan45 sudan45 marked this pull request as draft January 3, 2025 11:25
@sudan45 sudan45 force-pushed the feature/remove-dref-imminent-fields branch from 7749e74 to 556aefb Compare January 3, 2025 11:28
@susilnem susilnem changed the base branch from develop to project/dref-imminent January 4, 2025 07:23
@sudan45 sudan45 force-pushed the feature/remove-dref-imminent-fields branch 3 times, most recently from fd42bcb to e37477b Compare January 6, 2025 10:41
@susilnem susilnem force-pushed the feature/remove-dref-imminent-fields branch from e37477b to 77d0b87 Compare January 8, 2025 05:24
@susilnem susilnem force-pushed the feature/remove-dref-imminent-fields branch from 44d6e74 to 60a0368 Compare January 9, 2025 14:26
@susilnem susilnem marked this pull request as ready for review January 28, 2025 10:43
Copy link
Collaborator

@Rup-Narayan-Rajbanshi Rup-Narayan-Rajbanshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, few comments.

Comment on lines +461 to +527
# 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")}
)
Copy link
Collaborator

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.

@Rup-Narayan-Rajbanshi Rup-Narayan-Rajbanshi merged commit 19a8263 into project/dref-imminent Jan 28, 2025
3 checks passed
@susilnem susilnem deleted the feature/remove-dref-imminent-fields branch January 28, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants