diff --git a/CHANGELOG.md b/CHANGELOG.md index a13c2f8f0..51417aa7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ - add a new Activity tag, Strategic Allocation Pot (SAP), code 8 - model a single row of csv data that contains actual, refund and activity comments +- the new actual, refund and activity importer no longer accepts negative actual + values ## Release 141 - 2023-12-04 diff --git a/app/models/import/csv/activity_actual_refund_comment/row.rb b/app/models/import/csv/activity_actual_refund_comment/row.rb index 40eacf5de..cf980294c 100644 --- a/app/models/import/csv/activity_actual_refund_comment/row.rb +++ b/app/models/import/csv/activity_actual_refund_comment/row.rb @@ -135,6 +135,12 @@ def receiving_organisation_iati_reference @errors["Actual Value"] = [original_actual_value, I18n.t("import.csv.activity_actual_refund_comment.errors.financial_value")] return false end + + if actual_value.negative? + @errors["Actual Value"] = [original_actual_value, I18n.t("import.csv.activity_actual_refund_comment.errors.default.negative")] + return false + end + true end diff --git a/config/locales/import/csv/actiity_actual_refund_comment/errors.en.yml b/config/locales/import/csv/actiity_actual_refund_comment/errors.en.yml index fe5830bcb..265e27c3c 100644 --- a/config/locales/import/csv/actiity_actual_refund_comment/errors.en.yml +++ b/config/locales/import/csv/actiity_actual_refund_comment/errors.en.yml @@ -6,6 +6,7 @@ en: errors: default: required: Is required + negative: Cannot be negative financial_quarter: Must be 1, 2, 3 or 4 financial_year: Must be a four digit year financial_value: Must be a financial value diff --git a/spec/models/import/csv/activity_actual_refund_comment/row_spec.rb b/spec/models/import/csv/activity_actual_refund_comment/row_spec.rb index e2ef45958..1b184c666 100644 --- a/spec/models/import/csv/activity_actual_refund_comment/row_spec.rb +++ b/spec/models/import/csv/activity_actual_refund_comment/row_spec.rb @@ -297,6 +297,16 @@ end context "when the actual value is a number" do + context "and the number is negative" do + let(:csv_row) { valid_csv_row(actual: "-10000", refund: "0", comment: "") } + + it "is invaid with an error message and the original value" do + expect(subject).to be_invalid + expect(error_for_column("Actual Value").message).to eql "Cannot be negative" + expect(error_for_column("Actual Value").value).to eql "-10000" + end + end + context "and the refund value is zero" do context "and there is no comment" do let(:csv_row) { valid_csv_row(actual: "10000", refund: "0", comment: "") }