diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 7d1274540..b2adf9fa1 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -95,6 +95,8 @@ module DerivedVariables::LettingsLogVariables set_housingneeds_fields if housingneeds? + self.uprn_known = 0 if address_answered_without_uprn? + if uprn_known&.zero? self.uprn = nil end @@ -310,6 +312,10 @@ private self.county = nil end + def address_answered_without_uprn? + [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023 + end + def get_lar return 1 if rent_type == 2 return 2 if rent_type == 1 diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb index 308a62bb8..6532b228f 100644 --- a/app/models/derived_variables/sales_log_variables.rb +++ b/app/models/derived_variables/sales_log_variables.rb @@ -24,6 +24,8 @@ module DerivedVariables::SalesLogVariables self.hhmemb = number_of_household_members self.hhtype = household_type + self.uprn_known = 0 if address_answered_without_uprn? + if uprn_known&.zero? self.uprn = nil end @@ -148,4 +150,8 @@ private def only_one_elder? total_elder == 1 && total_adult.zero? && totchild.zero? end + + def address_answered_without_uprn? + [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023 + end end diff --git a/spec/models/form/lettings/questions/uprn_spec.rb b/spec/models/form/lettings/questions/uprn_spec.rb index b11ddc7d9..98599b99f 100644 --- a/spec/models/form/lettings/questions/uprn_spec.rb +++ b/spec/models/form/lettings/questions/uprn_spec.rb @@ -62,11 +62,13 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do postcode_full: "AA1 1AA", la: "E09000003", uprn_known:, + uprn:, ) end context "when uprn known nil" do let(:uprn_known) { nil } + let(:uprn) { nil } it "returns formatted value" do expect(question.get_extra_check_answer_value(log)).to be_nil @@ -75,6 +77,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do context "when uprn known" do let(:uprn_known) { 1 } + let(:uprn) { 123_456_789 } it "returns formatted value" do expect(question.get_extra_check_answer_value(log)).to eq( @@ -85,6 +88,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do context "when uprn not known" do let(:uprn_known) { 0 } + let(:uprn) { nil } it "returns formatted value" do expect(question.get_extra_check_answer_value(log)).to be_nil diff --git a/spec/models/form/sales/questions/uprn_spec.rb b/spec/models/form/sales/questions/uprn_spec.rb index 3d9a22a14..e1a1491ad 100644 --- a/spec/models/form/sales/questions/uprn_spec.rb +++ b/spec/models/form/sales/questions/uprn_spec.rb @@ -56,18 +56,19 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do let(:log) do create( :sales_log, - :completed, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", postcode_full: "AA1 1AA", la: "E09000003", uprn_known:, + uprn:, ) end context "when uprn known nil" do let(:uprn_known) { nil } + let(:uprn) { nil } it "returns formatted value" do expect(question.get_extra_check_answer_value(log)).to be_nil @@ -76,6 +77,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do context "when uprn known" do let(:uprn_known) { 1 } + let(:uprn) { 123_456_789 } it "returns formatted value" do expect(question.get_extra_check_answer_value(log)).to eq( @@ -86,6 +88,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do context "when uprn not known" do let(:uprn_known) { 0 } + let(:uprn) { nil } it "returns formatted value" do expect(question.get_extra_check_answer_value(log)).to be_nil