Browse Source

CLDC-1938 Fix location import (#1375)

* Fix location import

* Get postcode from full postcode field
pull/1376/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
aab205624a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/services/imports/sales_logs_import_service.rb
  2. 4
      spec/fixtures/imports/sales_logs/discounted_ownership_sales_log.xml
  3. 46
      spec/services/imports/sales_logs_import_service_spec.rb

16
app/services/imports/sales_logs_import_service.rb

@ -97,7 +97,7 @@ module Imports
attributes["pregla"] = 1 if string_or_nil(xml_doc, "PREGLA") == "Yes"
attributes["pregghb"] = 1 if string_or_nil(xml_doc, "PREGHBA") == "Yes"
attributes["pregother"] = 1 if string_or_nil(xml_doc, "PREGOTHER") == "Yes"
attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2")
attributes["ppostcode_full"] = parse_postcode(string_or_nil(xml_doc, "Q7Postcode"))
attributes["prevloc"] = string_or_nil(xml_doc, "Q7ONSLACode")
attributes["ppcodenk"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) # Q7UNKNOWNPOSTCODE check mapping
attributes["ppostc1"] = string_or_nil(xml_doc, "PPOSTC1")
@ -124,7 +124,7 @@ module Imports
attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes)
attributes["pcode1"] = string_or_nil(xml_doc, "PCODE1")
attributes["pcode2"] = string_or_nil(xml_doc, "PCODE2")
attributes["postcode_full"] = compose_postcode(xml_doc, "PCODE1", "PCODE2")
attributes["postcode_full"] = parse_postcode(string_or_nil(xml_doc, "Q14Postcode"))
attributes["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given
attributes["soctenant"] = soctenant(attributes)
attributes["ethnic_group2"] = nil # 23/24 variable
@ -134,7 +134,10 @@ module Imports
# Required for our form invalidated questions (not present in import)
attributes["previous_la_known"] = 1 if attributes["prevloc"].present? && attributes["ppostcode_full"].blank?
attributes["la_known"] = 1 if attributes["la"].present? && attributes["postcode_full"].blank?
if attributes["la"].present? && attributes["postcode_full"].blank?
attributes["la_known"] = 1
attributes["is_la_inferred"] = false
end
# Sets the log creator
owner_id = meta_field_value(xml_doc, "owner-user-id").strip
@ -439,6 +442,12 @@ module Imports
end
end
def parse_postcode(postcode)
return if postcode.blank?
UKPostcode.parse(postcode).to_s
end
def set_default_values(attributes)
attributes["armedforcesspouse"] ||= 7
attributes["hhregres"] ||= 8
@ -452,6 +461,7 @@ module Imports
if [attributes["pregyrha"], attributes["pregla"], attributes["pregghb"], attributes["pregother"]].all?(&:blank?)
attributes["pregblank"] = 1
end
attributes["pcodenk"] ||= 1
# buyer 1 characteristics
attributes["age1_known"] ||= 1

4
spec/fixtures/imports/sales_logs/discounted_ownership_sales_log.xml vendored

@ -33,7 +33,7 @@
<Q11Bedrooms override-field="">3</Q11Bedrooms>
<Q12PropertyType>3 House</Q12PropertyType>
<Q13BuildingType>1 Purpose built</Q13BuildingType>
<Q14Postcode override-field="">SW1A 1AA</Q14Postcode>
<Q14Postcode override-field="">GL519EX</Q14Postcode>
<!-- replace with commented options to test in the future -->
<!-- <Q14PropertyLocation>Westminster</Q14PropertyLocation>
<Q14ONSLACode>E09000033</Q14ONSLACode> -->
@ -208,7 +208,7 @@
<!-- replace with commented options to test in the future -->
<!-- <Q6PrevTenure/> -->
<Q6PrevTenure>3 Private tenant</Q6PrevTenure>
<Q7Postcode override-field="">GL51 9EX</Q7Postcode>
<Q7Postcode override-field="">GL519EX</Q7Postcode>
<Q7UnknownPostcode/>
<Q7PrevLocation>Cheltenham</Q7PrevLocation>
<Q7ONSLACode>E07000078</Q7ONSLACode>

46
spec/services/imports/sales_logs_import_service_spec.rb

@ -754,6 +754,52 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.buy2livein).to eq(nil)
end
end
context "when setting location fields" do
let(:sales_log_id) { "outright_sale_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "correctly sets LA if postcode is not given" do
sales_log_xml.at_xpath("//xmlns:Q14ONSLACode").content = "E07000142"
sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.pcodenk).to eq(1) # postcode not known
expect(sales_log&.is_la_inferred).to eq(false)
expect(sales_log&.la_known).to eq(1) # la known
expect(sales_log&.la).to eq("E07000142")
expect(sales_log&.status).to eq("completed")
end
it "correctly sets previous LA if postcode is not given" do
sales_log_xml.at_xpath("//xmlns:Q7ONSLACode").content = "E07000142"
sales_log_xml.at_xpath("//xmlns:Q7Postcode").content = ""
sales_log_xml.at_xpath("//xmlns:Q7UnknownPostcode").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.ppcodenk).to eq(1) # previous postcode not known
expect(sales_log&.is_previous_la_inferred).to eq(false)
expect(sales_log&.previous_la_known).to eq(1) # la known
expect(sales_log&.prevloc).to eq("E07000142")
expect(sales_log&.status).to eq("completed")
end
it "correctly sets posctode if given" do
sales_log_xml.at_xpath("//xmlns:Q7Postcode").content = "GL519EX"
sales_log_xml.at_xpath("//xmlns:Q7UnknownPostcode").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.ppcodenk).to eq(0)
expect(sales_log&.ppostcode_full).to eq("GL51 9EX")
expect(sales_log&.status).to eq("completed")
end
end
end
end
end

Loading…
Cancel
Save