diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index aec3dd714..39bd6a917 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -166,6 +166,18 @@ module Imports attributes["address_line2"] = string_or_nil(xml_doc, "AddressLine2") attributes["town_or_city"] = string_or_nil(xml_doc, "TownCity") attributes["county"] = string_or_nil(xml_doc, "County") + + attributes["proplen_asked"] = 0 if attributes["proplen"]&.positive? + attributes["proplen_asked"] = 1 if attributes["proplen"]&.zero? + + attributes["prevshared"] = unsafe_string_as_integer(xml_doc, "PREVSHARED") + attributes["ethnicbuy2"] = unsafe_string_as_integer(xml_doc, "P2Eth") + attributes["ethnic_group2"] = ethnic_group(attributes["ethnicbuy2"]) + attributes["nationalbuy2"] = unsafe_string_as_integer(xml_doc, "P2Nat") + attributes["buy2living"] = unsafe_string_as_integer(xml_doc, "buy2livein") + + attributes["staircasesale"] = unsafe_string_as_integer(xml_doc, "STAIRCASESALE") + attributes["prevtenbuy2"] = unsafe_string_as_integer(xml_doc, "PREVTENBUY2") end # Sets the log creator @@ -297,7 +309,9 @@ module Imports student_not_child_value_check discounted_sale_value_check buyer_livein_value_check - percentage_discount_value_check] + percentage_discount_value_check + uprn_known + uprn_confirmed] end def check_status_completed(sales_log, previous_status) @@ -476,12 +490,14 @@ module Imports safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") when 2 safe_string_as_decimal(xml_doc, "Q37MonthlyCharges") + when 3 + safe_string_as_decimal(xml_doc, "Q44MonthlyCharges") end end def ownership_from_type(attributes) case attributes["type"] - when 2, 24, 18, 16, 28, 31, 30 + when 2, 24, 18, 16, 28, 31, 30, 32 1 # shared ownership when 8, 14, 27, 9, 29, 21, 22 2 # discounted ownership @@ -564,6 +580,8 @@ module Imports attributes["sex1"] ||= "R" attributes["ethnic_group"] ||= 17 attributes["ethnic"] ||= 17 + # attributes["ethnic_group2"] ||= 17 + # attributes["ethnicbuy2"] ||= 17 attributes["national"] ||= 13 attributes["ecstat1"] ||= 10 attributes["income1nk"] ||= attributes["income1"].present? ? 0 : 1 diff --git a/spec/fixtures/imports/sales_logs/outright_sale_sales_log.xml b/spec/fixtures/imports/sales_logs/outright_sale_sales_log.xml index abca3fdde..ce17ff3fc 100644 --- a/spec/fixtures/imports/sales_logs/outright_sale_sales_log.xml +++ b/spec/fixtures/imports/sales_logs/outright_sale_sales_log.xml @@ -280,6 +280,7 @@ 300000 + 1 diff --git a/spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml b/spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml index 6e0c11174..b69cb22c2 100644 --- a/spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml +++ b/spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml @@ -24,6 +24,7 @@ 2 No 1 Yes + 2 No 2 Yes @@ -32,6 +33,12 @@ 2 1 Flat or maisonette 1 Purpose built + + + + + + SW1A 1AA Westminster E09000033 @@ -47,6 +54,8 @@ + + diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index d5cf858ca..2e7eea168 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -220,6 +220,87 @@ RSpec.describe Imports::SalesLogsImportService do end end + context "with 23/24 logs" do + around do |example| + Timecop.freeze(Time.zone.local(2023, 4, 1)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + + before do + sales_log_xml.at_xpath("//xmlns:DAY").content = "10" + sales_log_xml.at_xpath("//xmlns:MONTH").content = "4" + sales_log_xml.at_xpath("//xmlns:YEAR").content = "2023" + sales_log_xml.at_xpath("//xmlns:UPRN").content = "" + sales_log_xml.at_xpath("//xmlns:AddressLine1").content = "address 1" + sales_log_xml.at_xpath("//xmlns:AddressLine2").content = "address 2" + sales_log_xml.at_xpath("//xmlns:TownCity").content = "towncity" + sales_log_xml.at_xpath("//xmlns:County").content = "county" + sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = "A1 1AA" + end + + context "with outright sale type" do + let(:sales_log_id) { "outright_sale_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:Q44MonthlyCharges").content = "40" + end + + it "successfully creates a completed outright sale log" do + 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) + end + end + + context "with shared sale type" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes" + sales_log_xml.at_xpath("//xmlns:JointMore").content = "2 No" + sales_log_xml.at_xpath("//xmlns:PREVSHARED").content = "1" + sales_log_xml.at_xpath("//xmlns:Q16aProplen2").content = "0" + sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2" + sales_log_xml.at_xpath("//xmlns:P2Eth").content = "2 White: Irish" + sales_log_xml.at_xpath("//xmlns:P2Nat").content = "18 United Kingdom" + sales_log_xml.at_xpath("//xmlns:buy2livein").content = "1" + end + + it "successfully creates a completed shared sale log" do + 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.proplen_asked).to eq(1) + end + end + + context "with discounted sale type" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:PREVSHARED").content = "1" + sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2" + end + + it "successfully creates a completed shared sale log" do + 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) + end + end + end + context "and the mortgage soft validation is triggered (mortgage_value_check)" do let(:sales_log_id) { "discounted_ownership_sales_log" }