Browse Source

infer soctenant values if not given

pull/1443/head
Kat 3 years ago
parent
commit
f1d14c2b6e
  1. 15
      app/services/imports/sales_logs_import_service.rb
  2. 32
      spec/services/imports/sales_logs_import_service_spec.rb

15
app/services/imports/sales_logs_import_service.rb

@ -124,7 +124,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"] = soctenant(attributes) attributes["soctenant"] = 0 if attributes["ownershipsch"] == 1
attributes["ethnic_group2"] = nil # 23/24 variable attributes["ethnic_group2"] = nil # 23/24 variable
attributes["ethnicbuy2"] = nil # 23/24 variable attributes["ethnicbuy2"] = nil # 23/24 variable
attributes["prevshared"] = nil # 23/24 variable attributes["prevshared"] = nil # 23/24 variable
@ -364,17 +364,6 @@ module Imports
end end
end end
def soctenant(attributes)
return nil unless attributes["ownershipsch"] == 1
if attributes["frombeds"].blank? && attributes["fromprop"].blank? && attributes["socprevten"].blank?
2
else
1
end
# NO (2) if FROMBEDS, FROMPROP and socprevten are blank, and YES(1) if they are completed
end
def still_serving(xml_doc) def still_serving(xml_doc)
case unsafe_string_as_integer(xml_doc, "LeftArmedF") case unsafe_string_as_integer(xml_doc, "LeftArmedF")
when 4 when 4
@ -511,6 +500,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["fromprop"] ||= 0 if attributes["ownershipsch"] == 1
# buyer 1 characteristics # buyer 1 characteristics
attributes["age1_known"] ||= 1 attributes["age1_known"] ||= 1

32
spec/services/imports/sales_logs_import_service_spec.rb

@ -1142,6 +1142,38 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.extrabor).to be(3) expect(sales_log&.extrabor).to be(3)
end end
end end
context "when the fromprop is not answered" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q21PropertyType").content = ""
allow(logger).to receive(:warn).and_return(nil)
end
it "sets fromprop to don't know" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.fromprop).to be(0)
end
end
context "when the socprevten is not answered" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:PrevRentType").content = ""
allow(logger).to receive(:warn).and_return(nil)
end
it "sets socprevten to don't know" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.socprevten).to be(10)
end
end
end end
end end
end end

Loading…
Cancel
Save