From bd300cae0425fc256008c3f1baac726dd3faed9f Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 27 Jul 2023 08:10:11 +0100 Subject: [PATCH] CLDC-2592 Clear import fields (#1810) * Clear brent below absolute minimum * Clear beds over the max for the number of tenants --- .../validations/financial_validations.rb | 2 +- .../validations/property_validations.rb | 2 +- .../imports/lettings_logs_import_service.rb | 2 + .../lettings_logs_import_service_spec.rb | 61 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index dcb534efb..5a1775db4 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -213,7 +213,7 @@ private if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? && record.period.present? if record.weekly_value(record["brent"]) < rent_range.hard_min - record.errors.add :brent, I18n.t("validations.financial.brent.below_hard_min") + record.errors.add :brent, :below_hard_min, message: I18n.t("validations.financial.brent.below_hard_min") record.errors.add :beds, I18n.t("validations.financial.brent.beds.below_hard_min") record.errors.add :uprn, I18n.t("validations.financial.brent.uprn.below_hard_min") record.errors.add :la, I18n.t("validations.financial.brent.la.below_hard_min") diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index e9680facf..2f2d8d6b8 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -42,7 +42,7 @@ module Validations::PropertyValidations if record.hhmemb == 1 && record.is_shared_housing? && !record.beds.to_i.between?(1, 3) && record.beds.present? record.errors.add :unittype_gn, I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") - record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") + record.errors.add :beds, :one_three_bedroom_single_tenant_shared, message: I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") elsif record.is_shared_housing? && record.beds.present? && !record.beds.to_i.between?(1, 7) record.errors.add :unittype_gn, I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index 016b4251d..f1a86c023 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -317,11 +317,13 @@ 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[brent below_hard_min] => charges_attributes, %i[period wrong_rent_period] => %w[period], %i[layear renewal_just_moved] => %w[layear], %i[voiddate after_mrcdate] => %w[voiddate mrcdate majorrepairs], %i[tshortfall more_than_rent] => %w[tshortfall tshortfall_known], %i[scheme_id no_completed_locations] => %w[scheme_id location_id], + %i[beds one_three_bedroom_single_tenant_shared] => %w[beds], } (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 95301614d..738d2ed39 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -535,6 +535,29 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and beds over the max for the number of tenants" do + before do + lettings_log_xml.at_xpath("//xmlns:Q22").content = "4" + lettings_log_xml.at_xpath("//xmlns:HHMEMB").content = "1" + lettings_log_xml.at_xpath("//xmlns:Q23").content = "4" + end + + it "intercepts the relevant validation error" do + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the bedrooms 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.beds).to be_nil + end + end + context "and carehome charges and other charges are entered" do let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } @@ -770,6 +793,44 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and rent is lower than the absolute minimum expected for a property " do + before do + LaRentRange.create!( + ranges_rent_id: "2", + la: "E08000035", + beds: 2, + lettype: 1, + soft_min: 12.41, + soft_max: 89.54, + hard_min: 12.87, + hard_max: 100.99, + start_year: 2021, + ) + + lettings_log_xml.at_xpath("//xmlns:Q18ai").content = "8" + lettings_log_xml.at_xpath("//xmlns:Q18aii").content = "1" + lettings_log_xml.at_xpath("//xmlns:Q18aiii").content = "1" + lettings_log_xml.at_xpath("//xmlns:Q18aiv").content = "1" + lettings_log_xml.at_xpath("//xmlns:Q18av").content = "11" + lettings_log_xml.at_xpath("//xmlns:Q17").content = "1" + end + + it "intercepts the relevant validation error" do + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the charges answers" 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.tcharge).to be_nil + end + end + context "and location is not active during the period" do let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }