Browse Source

CLDC-3169: Infer soctenant from prevten / prevtenbuy2 (#2200)

* CLDC-3169: Infer soctentant from prevten

* Avoid default soctenant value

* Explicitly ensure soctenant nil for non shared ownership in bulk upload

* Fix linting
pull/2222/head
Rachael Booth 1 year ago committed by GitHub
parent
commit
9fdb4cee93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      app/models/derived_variables/sales_log_variables.rb
  2. 2
      app/models/form/sales/pages/buyer_previous.rb
  3. 4
      app/models/form/sales/questions/buyer_previous.rb
  4. 4
      app/models/sales_log.rb
  5. 13
      app/services/bulk_upload/sales/year2024/row_parser.rb
  6. 4
      spec/models/form/sales/pages/buyer_previous_spec.rb
  7. 31
      spec/models/form/sales/questions/buyer_previous_spec.rb
  8. 50
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

14
app/models/derived_variables/sales_log_variables.rb

@ -24,6 +24,10 @@ module DerivedVariables::SalesLogVariables
self.hhmemb = number_of_household_members self.hhmemb = number_of_household_members
self.hhtype = household_type self.hhtype = household_type
if saledate && form.start_year_after_2024?
self.soctenant = soctenant_from_prevten_values
end
self.uprn_known = 0 if address_answered_without_uprn? self.uprn_known = 0 if address_answered_without_uprn?
if uprn_known&.zero? if uprn_known&.zero?
@ -157,4 +161,14 @@ private
def address_answered_without_uprn? def address_answered_without_uprn?
[address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023 [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023
end end
def soctenant_from_prevten_values
return unless prevten && shared_ownership_scheme?
prevten_was_social_housing? ? 1 : 2
end
def prevten_was_social_housing?
[1, 2].include?(prevten) || [1, 2].include?(prevtenbuy2)
end
end end

2
app/models/form/sales/pages/buyer_previous.rb

@ -2,7 +2,7 @@ class Form::Sales::Pages::BuyerPrevious < ::Form::Page
def initialize(id, hsh, subsection, joint_purchase:) def initialize(id, hsh, subsection, joint_purchase:)
super(id, hsh, subsection) super(id, hsh, subsection)
@joint_purchase = joint_purchase @joint_purchase = joint_purchase
@depends_on = [{ "joint_purchase?" => joint_purchase }] @depends_on = [{ "joint_purchase?" => joint_purchase, "soctenant_is_inferred?" => false }]
end end
def questions def questions

4
app/models/form/sales/questions/buyer_previous.rb

@ -21,4 +21,8 @@ class Form::Sales::Questions::BuyerPrevious < ::Form::Question
"2" => { "value" => "No" }, "2" => { "value" => "No" },
} }
end end
def derived?
form.start_year_after_2024?
end
end end

4
app/models/sales_log.rb

@ -470,6 +470,10 @@ class SalesLog < Log
form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil].compact form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil].compact
end end
def soctenant_is_inferred?
form.start_year_after_2024?
end
def duplicates def duplicates
SalesLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:) SalesLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:)
end end

13
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -717,7 +717,6 @@ private
lanomagr: %i[field_97], lanomagr: %i[field_97],
frombeds: %i[field_98], frombeds: %i[field_98],
fromprop: %i[field_99], fromprop: %i[field_99],
soctenant: %i[field_98 field_99 field_100],
value: %i[field_101 field_114 field_125], value: %i[field_101 field_114 field_125],
equity: %i[field_102], equity: %i[field_102],
mortgage: %i[field_104 field_118 field_127], mortgage: %i[field_104 field_118 field_127],
@ -927,7 +926,7 @@ private
attributes["stairbought"] = field_87 attributes["stairbought"] = field_87
attributes["stairowned"] = field_88 attributes["stairowned"] = field_88
attributes["socprevten"] = field_100 attributes["socprevten"] = field_100
attributes["soctenant"] = [attributes["socprevten"], attributes["frombeds"], attributes["fromprop"]].any?(&:present?) ? 1 : 0 attributes["soctenant"] = infer_soctenant_from_prevten_and_prevtenbuy2
attributes["mortgageused"] = mortgageused attributes["mortgageused"] = mortgageused
attributes["uprn"] = field_22 attributes["uprn"] = field_22
@ -1123,6 +1122,16 @@ private
0 if field_62 == 1 0 if field_62 == 1
end end
def infer_soctenant_from_prevten_and_prevtenbuy2
return unless shared_ownership?
if [1, 2].include?(field_61) || [1, 2].include?(field_71.to_i)
1
else
2
end
end
def block_log_creation! def block_log_creation!
self.block_log_creation = true self.block_log_creation = true
end end

4
spec/models/form/sales/pages/buyer_previous_spec.rb

@ -42,13 +42,13 @@ RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do
let(:joint_purchase) { true } let(:joint_purchase) { true }
it "has the correct depends on" do it "has the correct depends on" do
expect(page.depends_on).to eq([{ "joint_purchase?" => true }]) expect(page.depends_on).to eq([{ "joint_purchase?" => true, "soctenant_is_inferred?" => false }])
end end
end end
context "when sales is not a joint purchase" do context "when sales is not a joint purchase" do
it "has the correct depends on" do it "has the correct depends on" do
expect(page.depends_on).to eq([{ "joint_purchase?" => false }]) expect(page.depends_on).to eq([{ "joint_purchase?" => false, "soctenant_is_inferred?" => false }])
end end
end end

31
spec/models/form/sales/questions/buyer_previous_spec.rb

@ -6,8 +6,15 @@ RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
let(:joint_purchase) { true } let(:joint_purchase) { true }
before do
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -42,10 +49,6 @@ RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do
expect(question.type).to eq("radio") expect(question.type).to eq("radio")
end end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct displayed_answer_options" do it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil)).to eq({ expect(question.displayed_answer_options(nil)).to eq({
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
@ -68,4 +71,24 @@ RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to eq(nil) expect(question.hint_text).to eq(nil)
end end
context "when form year is before 2024" do
before do
allow(form).to receive(:start_year_after_2024?).and_return(false)
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
end
context "when form year is >= 2024" do
before do
allow(form).to receive(:start_year_after_2024?).and_return(true)
end
it "is marked as derived" do
expect(question.derived?).to be true
end
end
end end

50
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -1264,13 +1264,59 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end end
describe "#soctenant" do describe "#soctenant" do
let(:attributes) { setup_section_params.merge({ field_99: "1" }) } context "when discounted ownership" do
let(:attributes) { valid_attributes.merge({ field_8: "2" }) }
it "is correctly set" do it "is set to nil" do
expect(parser.log.soctenant).to be_nil
end
end
context "when outright sale" do
let(:attributes) { valid_attributes.merge({ field_8: "3" }) }
it "is set to nil" do
expect(parser.log.soctenant).to be_nil
end
end
context "when shared ownership" do
context "when prevten is a social housing type" do
let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "1" }) }
it "is set to yes" do
expect(parser.log.soctenant).to be(1) expect(parser.log.soctenant).to be(1)
end end
end end
context "when prevten is not a social housing type" do
context "and prevtenbuy2 is a social housing type" do
let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "3", field_71: "2" }) }
it "is set to yes" do
expect(parser.log.soctenant).to be(1)
end
end
context "and prevtenbuy2 is not a social housing type" do
let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "3", field_71: "4" }) }
it "is set to no" do
expect(parser.log.soctenant).to be(2)
end
end
context "and prevtenbuy2 is blank" do
let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "3", field_71: nil }) }
it "is set to no" do
expect(parser.log.soctenant).to be(2)
end
end
end
end
end
describe "with living before purchase years for shared ownership more than 0" do describe "with living before purchase years for shared ownership more than 0" do
let(:attributes) { setup_section_params.merge({ field_8: "1", field_85: "1" }) } let(:attributes) { setup_section_params.merge({ field_8: "1", field_85: "1" }) }

Loading…
Cancel
Save