Skip to content

Commit

Permalink
[ch36049] FAM: validation on financial Findings local currency
Browse files Browse the repository at this point in the history
  • Loading branch information
emaciupe committed Jun 5, 2024
1 parent 537b304 commit 17a46dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/etools/applications/audit/serializers/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@ def get_number_of_financial_findings(self, obj):
def _validate_financial_findings(self, validated_data):
financial_findings = validated_data.get('financial_findings')
audited_expenditure = validated_data.get('audited_expenditure')
if not (financial_findings or audited_expenditure):
financial_findings_local = validated_data.get('financial_findings_local')
audited_expenditure_local = validated_data.get('audited_expenditure_local')
if not (financial_findings or audited_expenditure) and not (financial_findings_local or audited_expenditure_local):
return

if not financial_findings:
Expand All @@ -572,6 +574,14 @@ def _validate_financial_findings(self, validated_data):
if audited_expenditure and financial_findings and financial_findings > audited_expenditure:
raise serializers.ValidationError({'financial_findings': _('Cannot exceed Audited Expenditure')})

if not financial_findings_local:
financial_findings_local = self.instance.financial_findings_local if self.instance else None
if not audited_expenditure_local:
audited_expenditure_local = self.instance.audited_expenditure_local if self.instance else None

if audited_expenditure_local and financial_findings_local and financial_findings_local > audited_expenditure_local:
raise serializers.ValidationError({'financial_findings_local': _('Cannot exceed Audited Expenditure Local')})

def validate(self, validated_data):
self._validate_financial_findings(validated_data)
return validated_data
Expand Down
9 changes: 9 additions & 0 deletions src/etools/applications/audit/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,15 @@ def test_percent_of_audited_expenditure_invalid(self):
self.assertEqual(len(response.data), 1)
self.assertIn('financial_findings', response.data)

def test_percent_of_audited_expenditure_local_invalid(self):
response = self._do_update(self.auditor, {
'audited_expenditure_local': 1,
'financial_findings_local': 2
})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(len(response.data), 1)
self.assertIn('financial_findings_local', response.data)

def test_percent_of_audited_expenditure_valid(self):
response = self._do_update(self.auditor, {
'audited_expenditure': 2,
Expand Down

0 comments on commit 17a46dd

Please sign in to comment.