Browse Source

Get postcode from full postcode field

pull/1375/head
Kat 3 years ago
parent
commit
ebe9fae5e6
  1. 10
      app/services/imports/sales_logs_import_service.rb
  2. 4
      spec/fixtures/imports/sales_logs/discounted_ownership_sales_log.xml
  3. 17
      spec/services/imports/sales_logs_import_service_spec.rb

10
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["pregla"] = 1 if string_or_nil(xml_doc, "PREGLA") == "Yes"
attributes["pregghb"] = 1 if string_or_nil(xml_doc, "PREGHBA") == "Yes" attributes["pregghb"] = 1 if string_or_nil(xml_doc, "PREGHBA") == "Yes"
attributes["pregother"] = 1 if string_or_nil(xml_doc, "PREGOTHER") == "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["prevloc"] = string_or_nil(xml_doc, "Q7ONSLACode")
attributes["ppcodenk"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) # Q7UNKNOWNPOSTCODE check mapping attributes["ppcodenk"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) # Q7UNKNOWNPOSTCODE check mapping
attributes["ppostc1"] = string_or_nil(xml_doc, "PPOSTC1") attributes["ppostc1"] = string_or_nil(xml_doc, "PPOSTC1")
@ -124,7 +124,7 @@ module Imports
attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes) attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes)
attributes["pcode1"] = string_or_nil(xml_doc, "PCODE1") attributes["pcode1"] = string_or_nil(xml_doc, "PCODE1")
attributes["pcode2"] = string_or_nil(xml_doc, "PCODE2") 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["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given
attributes["soctenant"] = soctenant(attributes) attributes["soctenant"] = soctenant(attributes)
attributes["ethnic_group2"] = nil # 23/24 variable attributes["ethnic_group2"] = nil # 23/24 variable
@ -442,6 +442,12 @@ module Imports
end end
end end
def parse_postcode(postcode)
return if postcode.blank?
UKPostcode.parse(postcode).to_s
end
def set_default_values(attributes) def set_default_values(attributes)
attributes["armedforcesspouse"] ||= 7 attributes["armedforcesspouse"] ||= 7
attributes["hhregres"] ||= 8 attributes["hhregres"] ||= 8

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

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

17
spec/services/imports/sales_logs_import_service_spec.rb

@ -764,8 +764,7 @@ RSpec.describe Imports::SalesLogsImportService do
it "correctly sets LA if postcode is not given" do 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:Q14ONSLACode").content = "E07000142"
sales_log_xml.at_xpath("//xmlns:PCODE1").content = "" sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = ""
sales_log_xml.at_xpath("//xmlns:PCODE2").content = ""
sales_log_service.send(:create_log, sales_log_xml) sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id) sales_log = SalesLog.find_by(old_id: sales_log_id)
@ -778,8 +777,7 @@ RSpec.describe Imports::SalesLogsImportService do
it "correctly sets previous LA if postcode is not given" do 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:Q7ONSLACode").content = "E07000142"
sales_log_xml.at_xpath("//xmlns:PPOSTC1").content = "" sales_log_xml.at_xpath("//xmlns:Q7Postcode").content = ""
sales_log_xml.at_xpath("//xmlns:PPOSTC2").content = ""
sales_log_xml.at_xpath("//xmlns:Q7UnknownPostcode").content = "" sales_log_xml.at_xpath("//xmlns:Q7UnknownPostcode").content = ""
sales_log_service.send(:create_log, sales_log_xml) sales_log_service.send(:create_log, sales_log_xml)
@ -790,6 +788,17 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.prevloc).to eq("E07000142") expect(sales_log&.prevloc).to eq("E07000142")
expect(sales_log&.status).to eq("completed") expect(sales_log&.status).to eq("completed")
end 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
end end

Loading…
Cancel
Save