Browse Source

Only set soc tenant fields for 2022 or if they're given (#1908)

* Only set soc tenant fields for 2022 or if they're given

* Refactor
pull/1911/head v0.3.55
kosiakkatrina 1 year ago committed by GitHub
parent
commit
d3dec60f39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/services/imports/sales_logs_import_service.rb
  2. 38
      spec/services/imports/sales_logs_import_service_spec.rb

14
app/services/imports/sales_logs_import_service.rb

@ -1,5 +1,7 @@
module Imports module Imports
class SalesLogsImportService < LogsImportService class SalesLogsImportService < LogsImportService
include CollectionTimeHelper
def initialize(storage_service, logger = Rails.logger, allow_updates: false) def initialize(storage_service, logger = Rails.logger, allow_updates: false)
@logs_with_discrepancies = Set.new @logs_with_discrepancies = Set.new
@logs_overridden = Set.new @logs_overridden = Set.new
@ -124,7 +126,7 @@ module Imports
attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes) attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes)
attributes["postcode_full"] = parse_postcode(string_or_nil(xml_doc, "Q14Postcode")) attributes["postcode_full"] = parse_postcode(string_or_nil(xml_doc, "Q14Postcode"))
attributes["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given attributes["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given
attributes["soctenant"] = 0 if attributes["ownershipsch"] == 1 attributes["soctenant"] = 0 if set_soctenant_fields?(attributes)
attributes["previous_la_known"] = 1 if attributes["prevloc"].present? attributes["previous_la_known"] = 1 if attributes["prevloc"].present?
if attributes["la"].present? if attributes["la"].present?
@ -584,6 +586,12 @@ module Imports
end end
end end
def set_soctenant_fields?(attributes)
return false if attributes["ownershipsch"] != 1
%w[socprevten frombeds fromprop].any? { |field| attributes[field].present? } || collection_start_year_for_date(attributes["saledate"]) < 2023
end
def set_default_values(attributes) def set_default_values(attributes)
attributes["armedforcesspouse"] ||= 7 attributes["armedforcesspouse"] ||= 7
attributes["hhregres"] ||= 8 attributes["hhregres"] ||= 8
@ -600,8 +608,8 @@ module Imports
attributes["pcodenk"] ||= 1 attributes["pcodenk"] ||= 1
attributes["prevten"] ||= 0 attributes["prevten"] ||= 0
attributes["extrabor"] ||= 3 if attributes["mortgageused"] == 1 attributes["extrabor"] ||= 3 if attributes["mortgageused"] == 1
attributes["socprevten"] ||= 10 if attributes["ownershipsch"] == 1 attributes["socprevten"] ||= 10 if set_soctenant_fields?(attributes)
attributes["fromprop"] ||= 0 if attributes["ownershipsch"] == 1 attributes["fromprop"] ||= 0 if set_soctenant_fields?(attributes)
attributes["mortgagelender"] ||= 0 if attributes["mortgageused"] == 1 attributes["mortgagelender"] ||= 0 if attributes["mortgageused"] == 1
# buyer 1 characteristics # buyer 1 characteristics

38
spec/services/imports/sales_logs_import_service_spec.rb

@ -409,6 +409,42 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log = SalesLog.find_by(old_id: sales_log_id) sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.proplen_asked).to eq(1) expect(sales_log.proplen_asked).to eq(1)
end end
context "when setting soctenant fields" do
it "does not set soctenant value if none of the soctenant questions are answered" do
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = nil
sales_log_xml.at_xpath("//xmlns:PrevRentType").content = nil
sales_log_xml.at_xpath("//xmlns:Q21PropertyType").content = nil
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.to change(SalesLog, :count).by(1)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.soctenant).to eq(nil)
expect(sales_log.frombeds).to eq(nil)
expect(sales_log.fromprop).to eq(nil)
expect(sales_log.socprevten).to eq(nil)
end
it "sets soctenant to don't know if any of the soctenant questions are answered" do
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2"
sales_log_xml.at_xpath("//xmlns:PrevRentType").content = nil
sales_log_xml.at_xpath("//xmlns:Q21PropertyType").content = nil
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.to change(SalesLog, :count).by(1)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.soctenant).to eq(0)
expect(sales_log.frombeds).to eq(2)
expect(sales_log.fromprop).to eq(0)
expect(sales_log.socprevten).to eq(10)
end
end
end end
context "with discounted sale type" do context "with discounted sale type" do
@ -2091,6 +2127,7 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log = SalesLog.find_by(old_id: sales_log_id) sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.fromprop).to be(0) expect(sales_log&.fromprop).to be(0)
expect(sales_log&.soctenant).to be(0)
end end
end end
@ -2107,6 +2144,7 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log = SalesLog.find_by(old_id: sales_log_id) sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.socprevten).to be(10) expect(sales_log&.socprevten).to be(10)
expect(sales_log&.soctenant).to be(0)
end end
end end

Loading…
Cancel
Save