diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 7ec730b97..c7db4d99e 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -117,7 +117,7 @@ module Validations::FinancialValidations def validate_rent_period(record) if record.managing_organisation.present? && record.managing_organisation.rent_periods.present? && record.period && !record.managing_organisation.rent_periods.include?(record.period) - record.errors.add :period, I18n.t( + record.errors.add :period, :wrong_rent_period, message: I18n.t( "validations.financial.rent_period.invalid_for_org", org_name: record.managing_organisation.name, rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase, diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index 1d63d5d78..21d06a551 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -324,6 +324,7 @@ module Imports %i[location_id not_active] => %w[location_id scheme_id], %i[tcharge under_10] => charges_attributes, %i[brent over_hard_max] => charges_attributes, + %i[period wrong_rent_period] => %w[period], } (2..8).each do |person| diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index 07e863982..1a2768064 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -1263,6 +1263,53 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "when the organisation does not charge rent in certain period" do + let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } + let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) } + let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) } + + before do + FormHandler.instance.use_fake_forms! + create(:organisation_rent_period, organisation: managing_organisation, rent_period: 2) + + lettings_log_xml.at_xpath("//xmlns:DAY").content = "10" + lettings_log_xml.at_xpath("//xmlns:MONTH").content = "10" + lettings_log_xml.at_xpath("//xmlns:YEAR").content = "2022" + lettings_log_xml.at_xpath("//xmlns:Q17").content = "1" + lettings_log_xml.at_xpath("//xmlns:Q18c").content = "" + lettings_log_xml.at_xpath("//xmlns:Q18ai").content = "" + lettings_log_xml.at_xpath("//xmlns:Q18aiii").content = "" + lettings_log_xml.at_xpath("//xmlns:Q18aiv").content = "" + lettings_log_xml.at_xpath("//xmlns:Q18av").content = "" + lettings_log_xml.at_xpath("//xmlns:Q2b").content = "" + lettings_log_xml.at_xpath("//xmlns:_2cYears").content = "" + lettings_log_xml.at_xpath("//xmlns:P1Nat").content = "" + lettings_log_xml.at_xpath("//xmlns:_1cschemecode").content = "" + lettings_log_xml.at_xpath("//xmlns:_1cmangroupcode").content = "" + lettings_log_xml.at_xpath("//xmlns:Q25").content = "" + end + + after do + FormHandler.instance.use_real_forms! + Singleton.__init__(FormHandler) + end + + it "intercepts the relevant validation error" do + expect(logger).to receive(:warn).with("Log 0b4a68df-30cc-474a-93c0-a56ce8fdad3b: Removing period with error: DLUHC does not charge rent weekly for 52 weeks") + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the referral answer" do + allow(logger).to receive(:warn) + lettings_log_service.send(:create_log, lettings_log_xml) + lettings_log = LettingsLog.find_by(old_id: lettings_log_id) + + expect(lettings_log).not_to be_nil + expect(lettings_log.period).to be_nil + end + end + context "and the earnings is not a whole number" do let(:lettings_log_id) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" } let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }