Browse Source

Clear tshortfall if it is not positive

pull/1479/head
Kat 3 years ago
parent
commit
9c2de581e4
  1. 2
      app/models/validations/financial_validations.rb
  2. 6
      app/services/imports/lettings_logs_import_service.rb
  3. 41
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/financial_validations.rb

@ -79,7 +79,7 @@ module Validations::FinancialValidations
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.more_than_rent")
record.errors.add :brent, I18n.t("validations.financial.rent.less_than_shortfall")
elsif record.wtshortfall < 0.01
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.must_be_positive")
record.errors.add :tshortfall, :must_be_positive, message: I18n.t("validations.financial.tshortfall.must_be_positive")
end
end

6
app/services/imports/lettings_logs_import_service.rb

@ -367,6 +367,12 @@ module Imports
attributes.delete("supcharg")
attributes.delete("tcharge")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:tshortfall, :must_be_positive)
@logger.warn("Log #{lettings_log.old_id}: Removing tshortfall, because it is not positive/")
@logs_overridden << lettings_log.old_id
attributes.delete("tshortfall")
attributes.delete("tshortfall_known")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

41
spec/services/imports/lettings_logs_import_service_spec.rb

@ -384,7 +384,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the vacancy reason answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -407,7 +407,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the number offered answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -429,7 +429,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the working situation answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -453,7 +453,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the age answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -476,7 +476,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the bedrooms answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -506,7 +506,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the charges answers" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -530,7 +530,7 @@ RSpec.describe Imports::LettingsLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the charges answers" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
@ -545,6 +545,33 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and tshortfall is not positive" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
lettings_log_xml.at_xpath("//xmlns:Q18d").content = "1"
lettings_log_xml.at_xpath("//xmlns:Q6Ben").content = "1"
lettings_log_xml.at_xpath("//xmlns:Q18dyes").content = "0"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tshortfall, because it is not positive/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the tshortfall 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.tshortfall).to be_nil
expect(lettings_log.tshortfall_known).to be_nil
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"

Loading…
Cancel
Save