Browse Source

Lettings log import validations (#1463)

* Clear import fields failing non_temp_accommodation validation

* Clear joint tenancy if there is only 1 person in the household

* Clear offered if the value is above the maximum of 20

* Display error message on ecstat

* Remove ecstat if the income is too high for it
bulk-upload-sentence-case
kosiakkatrina 2 years ago committed by GitHub
parent
commit
fa8676b8ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/validations/financial_validations.rb
  2. 2
      app/models/validations/household_validations.rb
  3. 2
      app/models/validations/property_validations.rb
  4. 2
      app/models/validations/tenancy_validations.rb
  5. 21
      app/services/imports/lettings_logs_import_service.rb
  6. 2
      config/locales/en.yml
  7. 1
      spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  8. 111
      spec/services/imports/lettings_logs_import_service_spec.rb

1
app/models/validations/financial_validations.rb

@ -25,6 +25,7 @@ module Validations::FinancialValidations
if record.ecstat1 && record.weekly_net_income
if record.weekly_net_income > record.applicable_income_range.hard_max
record.errors.add :earnings, :over_hard_max, message: I18n.t("validations.financial.earnings.over_hard_max", hard_max: record.applicable_income_range.hard_max)
record.errors.add :ecstat1, :over_hard_max, message: I18n.t("validations.financial.ecstat.over_hard_max", hard_max: record.applicable_income_range.hard_max)
end
if record.weekly_net_income < record.applicable_income_range.hard_min

2
app/models/validations/household_validations.rb

@ -63,7 +63,7 @@ module Validations::HouseholdValidations
def validate_previous_housing_situation(record)
if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary?
record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation")
record.errors.add :prevten, :non_temp_accommodation, message: I18n.t("validations.household.prevten.non_temp_accommodation")
end
if record.age1.present? && record.age1 > 19 && record.previous_tenancy_was_foster_care?

2
app/models/validations/property_validations.rb

@ -16,7 +16,7 @@ module Validations::PropertyValidations
end
if record.offered.negative? || record.offered > 20
record.errors.add :offered, I18n.t("validations.property.offered.relet_number")
record.errors.add :offered, :over_20, message: I18n.t("validations.property.offered.relet_number")
end
end

2
app/models/validations/tenancy_validations.rb

@ -43,7 +43,7 @@ module Validations::TenancyValidations
return unless record.collection_start_year && record.joint
if record.hhmemb == 1 && record.joint != 2 && record.collection_start_year >= 2022
record.errors.add :joint, I18n.t("validations.tenancy.not_joint")
record.errors.add :joint, :not_joint_tenancy, message: I18n.t("validations.tenancy.not_joint")
record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member")
end
end

21
app/services/imports/lettings_logs_import_service.rb

@ -311,6 +311,27 @@ module Imports
attributes.delete("prevten")
attributes.delete("age1")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:prevten, :non_temp_accommodation)
@logger.warn("Log #{lettings_log.old_id}: Removing vacancy reason and previous tenancy since this accommodation is not temporary")
@logs_overridden << lettings_log.old_id
attributes.delete("prevten")
attributes.delete("rsnvac")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:joint, :not_joint_tenancy)
@logger.warn("Log #{lettings_log.old_id}: Removing joint tenancy as there is only 1 person in the household")
@logs_overridden << lettings_log.old_id
attributes.delete("joint")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:offered, :over_20)
@logger.warn("Log #{lettings_log.old_id}: Removing offered as the value is above the maximum of 20")
@logs_overridden << lettings_log.old_id
attributes.delete("offered")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:earnings, :over_hard_max)
@logger.warn("Log #{lettings_log.old_id}: Removing working situation because income is too high for it")
@logs_overridden << lettings_log.old_id
attributes.delete("ecstat1")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

2
config/locales/en.yml

@ -272,6 +272,8 @@ en:
local_authority:
general_needs: "Enter a value for the support charge between £0 and £60 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Enter a value for the support charge between £0 and £120 per week if the landlord is a local authority and it is a supported housing letting"
ecstat:
over_hard_max: "Net income of £%{hard_max} per week is too high for given the tenant’s working situation"
brent:
below_hard_min: "Rent is below the absolute minimum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms"

1
spec/fixtures/imports/logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

@ -119,6 +119,7 @@
<Q10-g>Yes</Q10-g>
<Q10-h/>
<Q10ia>2 No</Q10ia>
<joint>2 No</joint>
<Q10ib-1/>
<Q10ib-2/>
<Q10ib-3/>

111
spec/services/imports/lettings_logs_import_service_spec.rb

@ -366,6 +366,81 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and this is a non temporary acommodation" do
before do
lettings_log_xml.at_xpath("//xmlns:Q27").content = "9"
lettings_log_xml.at_xpath("//xmlns:Q11").content = "4"
lettings_log_xml.at_xpath("//xmlns:VDAY").content = ""
lettings_log_xml.at_xpath("//xmlns:VMONTH").content = ""
lettings_log_xml.at_xpath("//xmlns:VYEAR").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCDAY").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCMONTH").content = ""
lettings_log_xml.at_xpath("//xmlns:MRCYEAR").content = ""
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing vacancy reason and previous tenancy since this accommodation is not temporary/)
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.rsnvac).to be_nil
expect(lettings_log.prevten).to be_nil
end
end
context "and the number the property was relet is over 20" do
before do
lettings_log_xml.at_xpath("//xmlns:Q20").content = "25"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing offered as the value is above the maximum of 20/)
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.offered).to be_nil
end
end
context "and income over the max" do
before do
lettings_log_xml.at_xpath("//xmlns:Q8Money").content = "25000"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing working situation because income is too high for it/)
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.ecstat1).to be_nil
expect(lettings_log.earnings).to eq(25_000)
end
end
context "and the net income soft validation is triggered (net_income_value_check)" do
before do
lettings_log_xml.at_xpath("//xmlns:Q8a").content = "1 Weekly"
@ -560,5 +635,41 @@ RSpec.describe Imports::LettingsLogsImportService do
.to change(OrganisationRelationship, :count).by(1)
end
end
context "when this is a joint tenancy with 1 person in the household" do
let(:lettings_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }
let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) }
before do
lettings_log_xml.at_xpath("//xmlns:joint").content = "1"
lettings_log_xml.at_xpath("//xmlns:HHMEMB").content = "1"
lettings_log_xml.at_xpath("//xmlns:P2Age").content = ""
lettings_log_xml.at_xpath("//xmlns:P2Rel").content = ""
lettings_log_xml.at_xpath("//xmlns:P2Sex").content = ""
lettings_log_xml.at_xpath("//xmlns:P1Nat").content = "18"
lettings_log_xml.at_xpath("//xmlns:P2Eco").content = ""
lettings_log_xml.at_xpath("//xmlns:DAY").content = "2"
lettings_log_xml.at_xpath("//xmlns:MONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:YEAR").content = "2022"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing joint tenancy as there is only 1 person in the household/)
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.joint).to be_nil
expect(lettings_log.hhmemb).to eq(1)
end
end
end
end

Loading…
Cancel
Save