diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 9c291d7e7..4584cea52 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -111,8 +111,8 @@ module Validations::HouseholdValidations def validate_referral(record) if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs? - record.errors.add :referral, I18n.t("validations.household.referral.la_general_needs.internal_transfer") - record.errors.add :prevten, I18n.t("validations.household.prevten.la_general_needs.internal_transfer") + record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.prevten.la_general_needs.internal_transfer") + record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.referral.la_general_needs.internal_transfer") end if record.owning_organisation.provider_type == "LA" && record.local_housing_referral? diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb index f8fdfaf17..3b596c863 100644 --- a/app/services/imports/case_logs_import_service.rb +++ b/app/services/imports/case_logs_import_service.rb @@ -226,6 +226,11 @@ module Imports @logs_overridden << case_log.old_id attributes.delete("referral") save_case_log(attributes) + elsif case_log.errors.of_kind?(:referral, :internal_transfer_fixed_or_lifetime) + @logger.warn("Log #{case_log.old_id}: Removing internal transfer referral since previous tenancy is fixed terms or lifetime") + @logs_overridden << case_log.old_id + attributes.delete("referral") + save_case_log(attributes) else raise exception end @@ -378,7 +383,7 @@ module Imports age_refused = string_or_nil(xml_doc, "P#{index}AR") if age_refused.present? - if age_refused.casecmp("AGE_REFUSED").zero? + if age_refused.casecmp?("AGE_REFUSED") || age_refused.casecmp?("No") return 1 # No else return 0 # Yes diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb index db20cf117..dfe4ceb1b 100644 --- a/spec/services/imports/case_logs_import_service_spec.rb +++ b/spec/services/imports/case_logs_import_service_spec.rb @@ -178,6 +178,29 @@ RSpec.describe Imports::CaseLogsImportService do expect(case_log).not_to be_nil expect(case_log.referral).to be_nil end + + context "and this is an internal transfer from a previous fixed term tenancy" do + before do + case_log_xml.at_xpath("//xmlns:Q11").content = "30 Fixed term Local Authority General Needs tenancy" + case_log_xml.at_xpath("//xmlns:Q16").content = "1 Internal Transfer" + end + + it "intercepts the relevant validation error" do + expect(logger).to receive(:warn).with(/Removing internal transfer referral since previous tenancy is fixed terms or lifetime/) + expect { case_log_service.send(:create_log, case_log_xml) } + .not_to raise_error + end + + it "clears out the referral answer" do + allow(logger).to receive(:warn) + + case_log_service.send(:create_log, case_log_xml) + case_log = CaseLog.find_by(old_id: case_log_id) + + expect(case_log).not_to be_nil + expect(case_log.referral).to be_nil + end + end end end end