Browse Source

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

pull/1908/head
Kat 3 years ago
parent
commit
4096034c15
  1. 15
      app/services/imports/sales_logs_import_service.rb
  2. 38
      spec/services/imports/sales_logs_import_service_spec.rb

15
app/services/imports/sales_logs_import_service.rb

@ -1,5 +1,7 @@
module Imports
class SalesLogsImportService < LogsImportService
include CollectionTimeHelper
def initialize(storage_service, logger = Rails.logger, allow_updates: false)
@logs_with_discrepancies = Set.new
@logs_overridden = Set.new
@ -124,7 +126,7 @@ module Imports
attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes)
attributes["postcode_full"] = parse_postcode(string_or_nil(xml_doc, "Q14Postcode"))
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?
if attributes["la"].present?
@ -579,6 +581,13 @@ module Imports
end
end
def set_soctenant_fields?(attributes)
return false if attributes["ownershipsch"] != 1
return false if %w[socprevten frombeds fromprop].all? { |field| attributes[field].blank? } && collection_start_year_for_date(attributes["saledate"]) >= 2023
true
end
def set_default_values(attributes)
attributes["armedforcesspouse"] ||= 7
attributes["hhregres"] ||= 8
@ -595,8 +604,8 @@ module Imports
attributes["pcodenk"] ||= 1
attributes["prevten"] ||= 0
attributes["extrabor"] ||= 3 if attributes["mortgageused"] == 1
attributes["socprevten"] ||= 10 if attributes["ownershipsch"] == 1
attributes["fromprop"] ||= 0 if attributes["ownershipsch"] == 1
attributes["socprevten"] ||= 10 if set_soctenant_fields?(attributes)
attributes["fromprop"] ||= 0 if set_soctenant_fields?(attributes)
attributes["mortgagelender"] ||= 0 if attributes["mortgageused"] == 1
# buyer 1 characteristics

38
spec/services/imports/sales_logs_import_service_spec.rb

@ -384,6 +384,42 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.proplen_asked).to eq(1)
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
context "with discounted sale type" do
@ -1987,6 +2023,7 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.fromprop).to be(0)
expect(sales_log&.soctenant).to be(0)
end
end
@ -2003,6 +2040,7 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.socprevten).to be(10)
expect(sales_log&.soctenant).to be(0)
end
end

Loading…
Cancel
Save