Skip to content

Commit

Permalink
Add validation for budget and update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem authored and Rup-Narayan-Rajbanshi committed Jan 28, 2025
1 parent d7571ba commit 19a8263
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dref/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ProposedActionSerializer(serializers.ModelSerializer):

proposed_type_display = serializers.CharField(source="get_proposed_type_display", read_only=True)
activity = serializers.PrimaryKeyRelatedField(queryset=Sector.objects.all(), required=True)
budget = serializers.IntegerField(required=True)

class Meta:
model = ProposedAction
Expand Down Expand Up @@ -344,6 +345,7 @@ class Meta:


class DrefSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSerializer):
SUB_TOTAL = 75000
SURGE_DEPLOYMENT_COST = 10000
INDIRECT_COST_SURGE = 5800
INDIRECT_COST_NO_SURGE = 5000
Expand Down Expand Up @@ -471,6 +473,10 @@ def validate(self, data):
)
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")}
Expand Down
2 changes: 1 addition & 1 deletion dref/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ def test_dref_imminent(self):
title="health",
)
national_society = Country.objects.create(name="abc")
disaster_type = DisasterType.objects.create(name="abc")
disaster_type = DisasterType.objects.create(name="disaster 1")
data = {
"title": "Dref test title",
"type_of_onset": Dref.OnsetType.SUDDEN.value,
Expand Down

0 comments on commit 19a8263

Please sign in to comment.