diff --git a/src/etools/applications/audit/serializers/engagement.py b/src/etools/applications/audit/serializers/engagement.py index 819a7fae08..3950ed01a7 100644 --- a/src/etools/applications/audit/serializers/engagement.py +++ b/src/etools/applications/audit/serializers/engagement.py @@ -562,7 +562,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: @@ -570,9 +572,17 @@ def _validate_financial_findings(self, validated_data): 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) diff --git a/src/etools/applications/audit/tests/test_views.py b/src/etools/applications/audit/tests/test_views.py index 7adcc8c09d..8b68f8acab 100644 --- a/src/etools/applications/audit/tests/test_views.py +++ b/src/etools/applications/audit/tests/test_views.py @@ -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,