Browse Source

CLDC-2702 Prioritise addresses over UPRN on import (#1866)

* Prioritise addresses over UPRN

* Prioritise addresses over UPRN - sales

* Add test case
pull/1876/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
3b13dcc62f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/services/imports/lettings_logs_import_service.rb
  2. 10
      app/services/imports/sales_logs_import_service.rb
  3. 20
      spec/services/imports/lettings_logs_import_service_spec.rb
  4. 19
      spec/services/imports/sales_logs_import_service_spec.rb

10
app/services/imports/lettings_logs_import_service.rb

@ -200,13 +200,13 @@ module Imports
attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"]) attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"])
attributes["declaration"] = declaration(xml_doc) attributes["declaration"] = declaration(xml_doc)
attributes["uprn"] = string_or_nil(xml_doc, "UPRN")
attributes["uprn_known"] = attributes["uprn"].present? ? 1 : 0
attributes["uprn_confirmed"] = attributes["uprn"].present? ? 1 : 0
attributes["address_line1"] = string_or_nil(xml_doc, "AddressLine1") attributes["address_line1"] = string_or_nil(xml_doc, "AddressLine1")
attributes["address_line2"] = string_or_nil(xml_doc, "AddressLine2") attributes["address_line2"] = string_or_nil(xml_doc, "AddressLine2")
attributes["town_or_city"] = string_or_nil(xml_doc, "TownCity") attributes["town_or_city"] = string_or_nil(xml_doc, "TownCity")
attributes["county"] = string_or_nil(xml_doc, "County") attributes["county"] = string_or_nil(xml_doc, "County")
attributes["uprn"] = address_given?(attributes) ? nil : string_or_nil(xml_doc, "UPRN")
attributes["uprn_known"] = attributes["uprn"].present? ? 1 : 0
attributes["uprn_confirmed"] = attributes["uprn"].present? ? 1 : 0
set_partial_charges_to_zero(attributes) set_partial_charges_to_zero(attributes)
@ -651,5 +651,9 @@ module Imports
OrganisationRelationship.find_or_create_by!(parent_organisation_id:, child_organisation_id:) OrganisationRelationship.find_or_create_by!(parent_organisation_id:, child_organisation_id:)
end end
def address_given?(attributes)
attributes["address_line1"].present? && attributes["town_or_city"].present?
end
end end
end end

10
app/services/imports/sales_logs_import_service.rb

@ -153,13 +153,13 @@ module Imports
attributes["percentage_discount_value_check"] = 0 attributes["percentage_discount_value_check"] = 0
# 2023/34 attributes # 2023/34 attributes
attributes["uprn"] = string_or_nil(xml_doc, "UPRN")
attributes["uprn_known"] = attributes["uprn"].present? ? 1 : 0
attributes["uprn_confirmed"] = attributes["uprn"].present? ? 1 : 0
attributes["address_line1"] = string_or_nil(xml_doc, "AddressLine1") attributes["address_line1"] = string_or_nil(xml_doc, "AddressLine1")
attributes["address_line2"] = string_or_nil(xml_doc, "AddressLine2") attributes["address_line2"] = string_or_nil(xml_doc, "AddressLine2")
attributes["town_or_city"] = string_or_nil(xml_doc, "TownCity") attributes["town_or_city"] = string_or_nil(xml_doc, "TownCity")
attributes["county"] = string_or_nil(xml_doc, "County") attributes["county"] = string_or_nil(xml_doc, "County")
attributes["uprn"] = address_given?(attributes) ? nil : string_or_nil(xml_doc, "UPRN")
attributes["uprn_known"] = attributes["uprn"].present? ? 1 : 0
attributes["uprn_confirmed"] = attributes["uprn"].present? ? 1 : 0
attributes["proplen_asked"] = 0 if attributes["proplen"]&.positive? attributes["proplen_asked"] = 0 if attributes["proplen"]&.positive?
attributes["proplen_asked"] = 1 if attributes["proplen"]&.zero? attributes["proplen_asked"] = 1 if attributes["proplen"]&.zero?
@ -606,5 +606,9 @@ module Imports
applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log).select { |q| q.enabled?(sales_log) } }.flatten applicable_questions = sales_log.form.subsections.map { |s| s.applicable_questions(sales_log).select { |q| q.enabled?(sales_log) } }.flatten
applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id) - sales_log.optional_fields applicable_questions.filter { |q| q.unanswered?(sales_log) }.map(&:id) - sales_log.optional_fields
end end
def address_given?(attributes)
attributes["address_line1"].present? && attributes["town_or_city"].present?
end
end end
end end

20
spec/services/imports/lettings_logs_import_service_spec.rb

@ -1557,7 +1557,25 @@ RSpec.describe Imports::LettingsLogsImportService do
expect(lettings_log&.postcode_full).to eq("A1 1AA") expect(lettings_log&.postcode_full).to eq("A1 1AA")
end end
it "correctly sets address and uprn if uprn is given" do it "prioritises address and doesn't set UPRN if both address and UPRN is given" do
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log&.uprn_known).to eq(0) # no
expect(lettings_log&.uprn).to be_nil
expect(lettings_log&.uprn_confirmed).to eq(0)
expect(lettings_log&.address_line1).to eq("address 1")
expect(lettings_log&.address_line2).to eq("address 2")
expect(lettings_log&.town_or_city).to eq("towncity")
expect(lettings_log&.county).to eq("county")
expect(lettings_log&.postcode_full).to eq("A1 1AA")
end
it "correctly sets address and uprn if uprn is given and address isn't given" do
lettings_log_xml.at_xpath("//xmlns:AddressLine1").content = ""
lettings_log_xml.at_xpath("//xmlns:AddressLine2").content = ""
lettings_log_xml.at_xpath("//xmlns:TownCity").content = ""
lettings_log_xml.at_xpath("//xmlns:County").content = ""
lettings_log_service.send(:create_log, lettings_log_xml) lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id) lettings_log = LettingsLog.find_by(old_id: lettings_log_id)

19
spec/services/imports/sales_logs_import_service_spec.rb

@ -1684,7 +1684,24 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.postcode_full).to eq("A1 1AA") expect(sales_log&.postcode_full).to eq("A1 1AA")
end end
it "correctly sets address and uprn if uprn is given" do it "prioritises address and doesn't set UPRN if both address and UPRN is given" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.uprn_known).to eq(0) # no
expect(sales_log&.uprn).to be_nil
expect(sales_log&.address_line1).to eq("address 1")
expect(sales_log&.address_line2).to eq("address 2")
expect(sales_log&.town_or_city).to eq("towncity")
expect(sales_log&.county).to eq("county")
expect(sales_log&.postcode_full).to eq("A1 1AA")
end
it "correctly sets address and uprn if uprn is given and address is not given" do
sales_log_xml.at_xpath("//xmlns:AddressLine1").content = ""
sales_log_xml.at_xpath("//xmlns:AddressLine2").content = ""
sales_log_xml.at_xpath("//xmlns:TownCity").content = ""
sales_log_xml.at_xpath("//xmlns:County").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)

Loading…
Cancel
Save