Skip to content

Commit

Permalink
Merge pull request #3683 from unicef/36049-the-currency-of-the-fam-fi…
Browse files Browse the repository at this point in the history
…nancial-findings

[ch36049] FAM: validation on financial Findings local currency
  • Loading branch information
robertavram authored Jun 7, 2024
2 parents 2b2db1a + 99f97b8 commit 9948a61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/etools/applications/audit/serializers/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,17 +562,27 @@ 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:
financial_findings = self.instance.financial_findings if self.instance else None
if not audited_expenditure:
audited_expenditure = self.instance.audited_expenditure if self.instance else None

if audited_expenditure and financial_findings and financial_findings > audited_expenditure:
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):
validated_data = super().validate(validated_data)
self._validate_financial_findings(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 @@ -808,6 +808,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 9948a61

Please sign in to comment.