Browse Source

Remove shortfall if larger than rent

pull/1646/head
Kat 3 years ago
parent
commit
efad576d71
  1. 2
      app/models/validations/financial_validations.rb
  2. 3
      app/services/imports/lettings_logs_import_service.rb
  3. 38
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/financial_validations.rb

@ -92,7 +92,7 @@ module Validations::FinancialValidations
def validate_rent_amount(record)
if record.wtshortfall
if record.wrent && (record.wtshortfall > record.wrent)
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.more_than_rent")
record.errors.add :tshortfall, :more_than_rent, message: 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, :must_be_positive, message: I18n.t("validations.financial.tshortfall.must_be_positive")

3
app/services/imports/lettings_logs_import_service.rb

@ -326,7 +326,8 @@ module Imports
%i[brent over_hard_max] => charges_attributes,
%i[period wrong_rent_period] => %w[period],
%i[layear renewal_just_moved] => %w[layear],
%i[voiddate after_mrcdate] => %w[voiddate mrcdate],
%i[voiddate after_mrcdate] => %w[voiddate mrcdate majorrepairs],
%i[tshortfall more_than_rent] => %w[tshortfall tshortfall_known],
}
(2..8).each do |person|

38
spec/services/imports/lettings_logs_import_service_spec.rb

@ -1372,6 +1372,7 @@ RSpec.describe Imports::LettingsLogsImportService do
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing voiddate with error: Void date must be before the major repairs date if provided/)
expect(logger).to receive(:warn).with(/Removing mrcdate with error: Void date must be before the major repairs date if provided/)
expect(logger).to receive(:warn).with(/Removing majorrepairs with error: Void date must be before the major repairs date if provided/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
@ -1388,6 +1389,43 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "when shortfall is more than basic rent" 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: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:P1Nat").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18dyes").content = "200"
lettings_log_xml.at_xpath("//xmlns:Q18ai").content = "20"
lettings_log_xml.at_xpath("//xmlns:Q18aii").content = "20"
lettings_log_xml.at_xpath("//xmlns:Q18aiii").content = "40"
lettings_log_xml.at_xpath("//xmlns:Q18aiv").content = "20"
lettings_log_xml.at_xpath("//xmlns:Q18av").content = "100"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tshortfall with error: Enter a value less less than the basic rent amount/)
expect(logger).to receive(:warn).with(/Removing tshortfall_known with error: Enter a value less less than the basic rent amount/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the voiddate and mrcdate 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.tshortfall).to be_nil
expect(lettings_log.tshortfall_known).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) }

Loading…
Cancel
Save