Browse Source

Infer child uner 16 for sales

pull/2256/head
Kat 2 years ago
parent
commit
d32d913e3f
  1. 12
      app/models/derived_variables/sales_log_variables.rb
  2. 42
      app/models/form/lettings/questions/person_working_situation.rb
  3. 37
      app/models/form/sales/questions/person_working_situation.rb
  4. 10
      app/models/lettings_log.rb
  5. 10
      app/models/log.rb
  6. 6
      spec/models/form/sales/questions/person_working_situation_spec.rb
  7. 25
      spec/models/sales_log_spec.rb

12
app/models/derived_variables/sales_log_variables.rb

@ -36,6 +36,7 @@ module DerivedVariables::SalesLogVariables
if saledate && form.start_year_after_2024? if saledate && form.start_year_after_2024?
self.soctenant = soctenant_from_prevten_values self.soctenant = soctenant_from_prevten_values
child_under_16_constraints!
end end
self.uprn_known = 0 if address_answered_without_uprn? self.uprn_known = 0 if address_answered_without_uprn?
@ -124,6 +125,17 @@ private
end end
end end
def child_under_16_constraints!
start_index = joint_purchase? ? 3 : 2
(start_index..6).each do |idx|
if age_under_16?(idx)
self["ecstat#{idx}"] = 9
elsif public_send("ecstat#{idx}") == 9 && age_known?(idx)
self["ecstat#{idx}"] = nil
end
end
end
def household_type def household_type
return unless total_elder && total_adult && totchild return unless total_elder && total_adult && totchild

42
app/models/form/lettings/questions/person_working_situation.rb

@ -7,31 +7,31 @@ class Form::Lettings::Questions::PersonWorkingSituation < ::Form::Question
@type = "radio" @type = "radio"
@check_answers_card_number = person_index @check_answers_card_number = person_index
@hint_text = "" @hint_text = ""
@answer_options = ANSWER_OPTIONS
@person_index = person_index @person_index = person_index
@question_number = question_number @question_number = question_number
@answer_options = answer_options
end end
ANSWER_OPTIONS = { def answer_options
"1" => { "value" => "Full-time – 30 hours or more" }, { "1" => { "value" => "Full-time – 30 hours or more" },
"2" => { "value" => "Part-time – Less than 30 hours" }, "2" => { "value" => "Part-time – Less than 30 hours" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"3" => { "value" => "In government training into work, such as New Deal" }, "3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" }, "4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },
"8" => { "value" => "Unable to work because of long term sick or disability" }, "8" => { "value" => "Unable to work because of long term sick or disability" },
"5" => { "value" => "Retired" }, "5" => { "value" => "Retired" },
"9" => { "9" => {
"value" => "Child under 16", "value" => "Child under 16",
"depends_on" => [ "depends_on" => [
{ "age2_known" => 1 }, { "age#{@person_index}_known" => 1 },
{ "age2" => { "operator" => "<", "operand" => 16 } }, { "age#{@person_index}" => { "operator" => "<", "operand" => 16 } },
], ],
}, },
"0" => { "value" => "Other" }, "0" => { "value" => "Other" },
"divider" => { "value" => true }, "divider" => { "value" => true },
"10" => { "value" => "Person prefers not to say" }, "10" => { "value" => "Person prefers not to say" } }
}.freeze end
def question_number def question_number
base_question_number = case form.start_date.year base_question_number = case form.start_date.year

37
app/models/form/sales/questions/person_working_situation.rb

@ -4,7 +4,6 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question
@check_answer_label = "Person #{person_index}’s working situation" @check_answer_label = "Person #{person_index}’s working situation"
@header = "Which of these best describes Person #{person_index}’s working situation?" @header = "Which of these best describes Person #{person_index}’s working situation?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index @check_answers_card_number = person_index
@inferred_check_answers_value = [{ @inferred_check_answers_value = [{
"condition" => { "condition" => {
@ -14,21 +13,31 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question
}] }]
@person_index = person_index @person_index = person_index
@question_number = question_number @question_number = question_number
@answer_options = answer_options
end end
ANSWER_OPTIONS = { def answer_options
"1" => { "value" => "Full-time - 30 hours or more" }, {
"2" => { "value" => "Part-time - Less than 30 hours" }, "1" => { "value" => "Full-time - 30 hours or more" },
"3" => { "value" => "In government training into work, such as New Deal" }, "2" => { "value" => "Part-time - Less than 30 hours" },
"4" => { "value" => "Jobseeker" }, "3" => { "value" => "In government training into work, such as New Deal" },
"6" => { "value" => "Not seeking work" }, "4" => { "value" => "Jobseeker" },
"8" => { "value" => "Unable to work due to long term sick or disability" }, "6" => { "value" => "Not seeking work" },
"5" => { "value" => "Retired" }, "8" => { "value" => "Unable to work due to long term sick or disability" },
"0" => { "value" => "Other" }, "5" => { "value" => "Retired" },
"10" => { "value" => "Person prefers not to say" }, "0" => { "value" => "Other" },
"7" => { "value" => "Full-time student" }, "10" => { "value" => "Person prefers not to say" },
"9" => { "value" => "Child under 16" }, "7" => { "value" => "Full-time student" },
}.freeze "9" => {
"value" => "Child under 16",
"depends_on" => [
{ "saledate" => { "operator" => "<", "operand" => Time.zone.local(2024, 4, 1) } },
{ "age#{@person_index}_known" => 1 },
{ "age#{@person_index}" => { "operator" => "<", "operand" => 16 } },
],
},
}
end
def question_number def question_number
base_question_number = case form.start_date.year base_question_number = case form.start_date.year

10
app/models/lettings_log.rb

@ -556,12 +556,6 @@ class LettingsLog < Log
RETIREMENT_AGES[gender] RETIREMENT_AGES[gender]
end end
def age_known?(person_num)
return false unless person_num.is_a?(Integer)
!!public_send("age#{person_num}_known")&.zero?
end
def age_unknown?(person_num) def age_unknown?(person_num)
return false unless person_num.is_a?(Integer) return false unless person_num.is_a?(Integer)
@ -752,10 +746,6 @@ private
collection_start_year >= 2022 && !is_fixed_term_tenancy? collection_start_year >= 2022 && !is_fixed_term_tenancy?
end end
def age_under_16?(person_num)
public_send("age#{person_num}") && public_send("age#{person_num}") < 16
end
def process_postcode_changes! def process_postcode_changes!
self.postcode_full = upcase_and_remove_whitespace(postcode_full) self.postcode_full = upcase_and_remove_whitespace(postcode_full)
return if postcode_full.blank? return if postcode_full.blank?

10
app/models/log.rb

@ -277,6 +277,16 @@ class Log < ApplicationRecord
nationality_all_group&.zero? || nationality_all_group == 826 nationality_all_group&.zero? || nationality_all_group == 826
end end
def age_under_16?(person_num)
public_send("age#{person_num}") && public_send("age#{person_num}") < 16
end
def age_known?(person_num)
return false unless person_num.is_a?(Integer)
!!public_send("age#{person_num}_known")&.zero?
end
private private
# Handle logs that are older than previous collection start date # Handle logs that are older than previous collection start date

6
spec/models/form/sales/questions/person_working_situation_spec.rb

@ -32,7 +32,11 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
"0" => { "value" => "Other" }, "0" => { "value" => "Other" },
"10" => { "value" => "Person prefers not to say" }, "10" => { "value" => "Person prefers not to say" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" }, "9" => { "value" => "Child under 16",
"depends_on" =>
[{ "saledate" => { "operator" => "<", "operand" => Time.zone.local(2024, 4, 1) } },
{ "age2_known" => 1 },
{ "age2" => { "operator" => "<", "operand" => 16 } }] },
}) })
end end

25
spec/models/sales_log_spec.rb

@ -816,6 +816,31 @@ RSpec.describe SalesLog, type: :model do
expect(record_from_db["ppostcode_full"]).to eq(nil) expect(record_from_db["ppostcode_full"]).to eq(nil)
expect(record_from_db["prevloc"]).to eq(nil) expect(record_from_db["prevloc"]).to eq(nil)
end end
context "when validating household members derived vars" do
let!(:household_sales_log) do
create(
:sales_log,
:completed,
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
age6: 14,
saledate: Time.zone.local(2024, 5, 2),
)
end
it "correctly derives economic status for tenants under 16" do
record_from_db = described_class.find(household_sales_log.id)
expect(record_from_db["ecstat6"]).to eq(9)
end
it "correctly resets economic status when age changes from under 16" do
household_sales_log.update!(age6_known: 0, age6: 17)
record_from_db = described_class.find(household_sales_log.id)
expect(record_from_db["ecstat6"]).to eq(nil)
end
end
end end
it "errors if the property postcode is emptied" do it "errors if the property postcode is emptied" do

Loading…
Cancel
Save