Browse Source

CLDC-3169: Infer soctentant from prevten

pull/2200/head
Rachael Booth 2 years ago
parent
commit
a9e562f564
  1. 8
      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. 11
      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. 32
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

8
app/models/derived_variables/sales_log_variables.rb

@ -24,6 +24,10 @@ module DerivedVariables::SalesLogVariables
self.hhmemb = number_of_household_members
self.hhtype = household_type
if form.start_year_after_2024?
self.soctenant = prevten_was_social_housing? ? 1 : 2
end
self.uprn_known = 0 if address_answered_without_uprn?
if uprn_known&.zero?
@ -154,4 +158,8 @@ private
def address_answered_without_uprn?
[address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023
end
def prevten_was_social_housing?
[1, 2].include?(prevten) || [1, 2].include?(prevtenbuy2)
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:)
super(id, hsh, subsection)
@joint_purchase = joint_purchase
@depends_on = [{ "joint_purchase?" => joint_purchase }]
@depends_on = [{ "joint_purchase?" => joint_purchase, "soctenant_is_inferred?" => false }]
end
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" },
}
end
def derived?
form.start_year_after_2024?
end
end

4
app/models/sales_log.rb

@ -456,4 +456,8 @@ class SalesLog < Log
form.start_date.year < 2023 || uprn.blank? ? "postcode_full" : nil,
form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil].compact
end
def soctenant_is_inferred?
form.start_year_after_2024?
end
end

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

@ -716,7 +716,6 @@ private
lanomagr: %i[field_97],
frombeds: %i[field_98],
fromprop: %i[field_99],
soctenant: %i[field_98 field_99 field_100],
value: %i[field_101 field_114 field_125],
equity: %i[field_102],
mortgage: %i[field_104 field_118 field_127],
@ -924,7 +923,7 @@ private
attributes["stairbought"] = field_87
attributes["stairowned"] = field_88
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["uprn"] = field_22
@ -1119,6 +1118,14 @@ private
0 if field_62 == 1
end
def infer_soctenant_from_prevten_and_prevtenbuy2
if [1, 2].include?(field_61) || [1, 2].include?(field_71.to_i)
1
else
2
end
end
def block_log_creation!
self.block_log_creation = true
end

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

@ -32,13 +32,13 @@ RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do
let(:joint_purchase) { true }
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
context "when sales is not a joint purchase" 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

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_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
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
expect(question.page).to eq(page)
end
@ -42,10 +49,6 @@ RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil)).to eq({
"1" => { "value" => "Yes" },
@ -68,4 +71,24 @@ RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do
it "has the correct hint" do
expect(question.hint_text).to eq(nil)
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

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

@ -1136,13 +1136,41 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end
describe "#soctenant" do
let(:attributes) { setup_section_params.merge({ field_99: "1" }) }
context "when prevten is a social housing type" do
let(:attributes) { valid_attributes.merge({ field_61: "1" }) }
it "is correctly set" do
it "is set to yes" do
expect(parser.log.soctenant).to be(1)
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_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_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_61: "3", field_71: nil }) }
it "is set to no" do
expect(parser.log.soctenant).to be(2)
end
end
end
end
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" }) }

Loading…
Cancel
Save