Browse Source

CLDC-3546: Add error to managing org when it does not have relevant rent period (#2538)

* CLDC-3546: Add error to managing org when it does not have relevant rent period

* Add test for :skip_bu_error

* Fix managing org question id
pull/2534/head^2
Rachael Booth 5 months ago committed by GitHub
parent
commit
6a42978fab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      app/models/validations/financial_validations.rb
  2. 1
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  3. 4
      config/locales/en.yml
  4. 8
      spec/models/validations/financial_validations_spec.rb
  5. 12
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

7
app/models/validations/financial_validations.rb

@ -149,7 +149,12 @@ module Validations::FinancialValidations
unless record.managing_organisation.rent_periods.include? record.period unless record.managing_organisation.rent_periods.include? record.period
record.errors.add :period, :wrong_rent_period, message: I18n.t( record.errors.add :period, :wrong_rent_period, message: I18n.t(
"validations.financial.rent_period.invalid_for_org", "validations.financial.rent_period.invalid_for_org.period",
org_name: record.managing_organisation.name,
rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase,
)
record.errors.add :managing_organisation_id, :skip_bu_error, message: I18n.t(
"validations.financial.rent_period.invalid_for_org.managing_org",
org_name: record.managing_organisation.name, org_name: record.managing_organisation.name,
rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase, rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase,
) )

1
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -467,6 +467,7 @@ class BulkUpload::Lettings::Year2024::RowParser
fields.each do |field| fields.each do |field|
next if errors.include?(field) next if errors.include?(field)
next if error.type == :skip_bu_error
question = log.form.get_question(error.attribute, log) question = log.form.get_question(error.attribute, log)

4
config/locales/en.yml

@ -436,7 +436,9 @@ en:
under_10: "Enter a total charge that is at least £10.00 per week" under_10: "Enter a total charge that is at least £10.00 per week"
less_than_shortfall: "The total charge must be more than the outstanding amount" less_than_shortfall: "The total charge must be more than the outstanding amount"
rent_period: rent_period:
invalid_for_org: "%{org_name} does not use %{rent_period} as a rent period. Choose another rent period, or a data coordinator can add rent periods to your organisation" invalid_for_org:
period: "%{org_name} does not use %{rent_period} as a rent period. Choose another rent period, or a data coordinator can add rent periods to your organisation"
managing_org: "%{org_name} does not use %{rent_period} as a rent period. Set another rent period on this log, or a data coordinator can add rent periods to this organisation"
carehome: carehome:
out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}" out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}"
not_provided: "Enter how much rent and other charges the household pays %{period}" not_provided: "Enter how much rent and other charges the household pays %{period}"

8
spec/models/validations/financial_validations_spec.rb

@ -165,7 +165,13 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_period(record) financial_validator.validate_rent_period(record)
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t( .to include(match I18n.t(
"validations.financial.rent_period.invalid_for_org", "validations.financial.rent_period.invalid_for_org.period",
org_name: user.organisation.name,
rent_period: "every 4 weeks",
))
expect(record.errors["managing_organisation_id"])
.to include(match I18n.t(
"validations.financial.rent_period.invalid_for_org.managing_org",
org_name: user.organisation.name, org_name: user.organisation.name,
rent_period: "every 4 weeks", rent_period: "every 4 weeks",
)) ))

12
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -750,6 +750,18 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.errors[:field_15]).to eq(["You must answer tenant has seen the privacy notice"]) expect(parser.errors[:field_15]).to eq(["You must answer tenant has seen the privacy notice"])
end end
end end
context "when there is a :skip_bu_error error" do
let(:managing_org) { create(:organisation, :with_old_visible_id, rent_periods: [4, 1]) }
let(:attributes) { valid_attributes.merge({ field_123: 3, field_128: 80 }) }
it "does not add that error" do
parser.valid?
expect(parser.log.errors.map(&:attribute).sort).to eql(%i[managing_organisation_id period])
expect(parser.errors.map(&:attribute)).to eql(%i[field_123])
end
end
end end
describe "#validate_nulls" do describe "#validate_nulls" do

Loading…
Cancel
Save