Browse Source

CLDC-4269: Raise max hhmemb (#3332)

* CLDC-4269: update hhmemb question

* CLDC-4269: update counts in vars and validations

* CLDC-4269: update depends_on for person_known and update tests

* CLDC-4269: reformat

* CLDC-4269: update spec

* CLDC-4269: update spec

* CLDC-4269: cleanup

* CLDC-4269: cleanup

* CLDC-4352: refactoring

* CLDC-4269: move depends_on after person_index for safety

* CLDC-4269: comment for not fully implemented const
pull/3339/head
Nat Dean-Lewis 2 days ago committed by GitHub
parent
commit
8d6cd83549
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 9
      app/models/form/lettings/pages/person_known.rb
  3. 2
      app/models/form/lettings/questions/hhmemb.rb
  4. 3
      app/models/lettings_log.rb
  5. 8
      app/models/log.rb
  6. 1
      app/models/sales_log.rb
  7. 4
      app/models/validations/financial_validations.rb
  8. 35
      app/models/validations/soft_validations.rb
  9. 2
      config/locales/forms/2025/lettings/household_characteristics.en.yml
  10. 2
      config/locales/forms/2026/lettings/household_characteristics.en.yml
  11. 29
      spec/models/form/lettings/pages/person_known_spec.rb
  12. 12
      spec/models/validations/household_validations_spec.rb

2
app/models/derived_variables/lettings_log_variables.rb

@ -339,7 +339,7 @@ private
def infer_only_partner!(partner_number) def infer_only_partner!(partner_number)
return unless hhmemb return unless hhmemb
(2..hhmemb).each do |i| (2..people_with_details).each do |i|
next if i == partner_number next if i == partner_number
if ["P", nil].include?(public_send("relat#{i}")) if ["P", nil].include?(public_send("relat#{i}"))

9
app/models/form/lettings/pages/person_known.rb

@ -2,11 +2,18 @@ class Form::Lettings::Pages::PersonKnown < ::Form::Page
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super(id, hsh, subsection) super(id, hsh, subsection)
@id = "person_#{person_index}_known" @id = "person_#{person_index}_known"
@depends_on = (person_index..8).map { |index| { "hhmemb" => index } }
@person_index = person_index @person_index = person_index
@depends_on = depends_on
end end
def questions def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown.new(nil, nil, self, person_index: @person_index)] @questions ||= [Form::Lettings::Questions::DetailsKnown.new(nil, nil, self, person_index: @person_index)]
end end
def depends_on
[{ "hhmemb" => {
"operator" => ">=",
"operand" => @person_index,
} }]
end
end end

2
app/models/form/lettings/questions/hhmemb.rb

@ -5,7 +5,7 @@ class Form::Lettings::Questions::Hhmemb < ::Form::Question
@type = "numeric" @type = "numeric"
@width = 2 @width = 2
@check_answers_card_number = 0 @check_answers_card_number = 0
@max = 8 @max = 15
@min = 1 @min = 1
@step = 1 @step = 1
@question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR) @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR)

3
app/models/lettings_log.rb

@ -191,6 +191,7 @@ class LettingsLog < Log
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 11 => 51, 1 => 52, 10 => 53 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 11 => 51, 1 => 52, 10 => 53 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 sexrab1 ecstat1 tcharge household_charge chcharge].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 sexrab1 ecstat1 tcharge household_charge chcharge].freeze
MAX_PEOPLE_WITH_DETAILS = 8 # This is not yet used in all lettings validations etc. so check for other occurrences of this concept if updating this
RENT_TYPE = { RENT_TYPE = {
social_rent: 0, social_rent: 0,
affordable_rent: 1, affordable_rent: 1,
@ -284,7 +285,7 @@ class LettingsLog < Log
range = ALLOWED_INCOME_RANGES[ecstat1].clone range = ALLOWED_INCOME_RANGES[ecstat1].clone
if hhmemb > 1 if hhmemb > 1
(2..hhmemb).each do |person_index| (2..people_with_details).each do |person_index|
ecstat = self["ecstat#{person_index}"] ecstat = self["ecstat#{person_index}"]
if ecstat.nil? if ecstat.nil?

8
app/models/log.rb

@ -204,6 +204,14 @@ class Log < ApplicationRecord
false false
end end
def people_with_details
[hhmemb || max_people_with_details, max_people_with_details].min
end
def max_people_with_details
self.class::MAX_PEOPLE_WITH_DETAILS
end
def ethnic_refused? def ethnic_refused?
ethnic_group == 17 ethnic_group == 17
end end

1
app/models/sales_log.rb

@ -104,6 +104,7 @@ class SalesLog < Log
OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze
DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 sexrab1 ecstat1 postcode_full uprn address_line1].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 sexrab1 ecstat1 postcode_full uprn address_line1].freeze
MAX_PEOPLE_WITH_DETAILS = 6 # This is not yet used in all sales validations etc. so check for other occurrences of this concept if updating this
def lettings? def lettings?
false false

4
app/models/validations/financial_validations.rb

@ -41,7 +41,7 @@ module Validations::FinancialValidations
:over_hard_max, :over_hard_max,
message: I18n.t("validations.lettings.financial.hhmemb.earnings_over_hard_max", earnings: format_as_currency(record.earnings), frequency:), message: I18n.t("validations.lettings.financial.hhmemb.earnings_over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
) )
(1..record.hhmemb).each do |n| (1..record.people_with_details).each do |n|
record.errors.add( record.errors.add(
"ecstat#{n}", "ecstat#{n}",
:over_hard_max, :over_hard_max,
@ -70,7 +70,7 @@ module Validations::FinancialValidations
:under_hard_min, :under_hard_min,
message: I18n.t("validations.lettings.financial.hhmemb.earnings_under_hard_min", earnings: format_as_currency(record.earnings), frequency:), message: I18n.t("validations.lettings.financial.hhmemb.earnings_under_hard_min", earnings: format_as_currency(record.earnings), frequency:),
) )
(1..record.hhmemb).each do |n| (1..record.people_with_details).each do |n|
record.errors.add( record.errors.add(
"ecstat#{n}", "ecstat#{n}",
:under_hard_min, :under_hard_min,

35
app/models/validations/soft_validations.rb

@ -208,8 +208,7 @@ module Validations::SoftValidations
def multiple_partners? def multiple_partners?
return unless hhmemb return unless hhmemb
max_person_with_details = sales? ? [hhmemb, 6].min : [hhmemb, 8].min (2..people_with_details).many? { |n| public_send("relat#{n}") == "P" }
(2..max_person_with_details).many? { |n| public_send("relat#{n}") == "P" }
end end
def at_least_one_working_situation_is_sickness_and_household_sickness_is_no? def at_least_one_working_situation_is_sickness_and_household_sickness_is_no?
@ -219,22 +218,18 @@ module Validations::SoftValidations
private private
def all_tenants_age_and_gender_information_completed? def all_tenants_age_and_gender_information_completed?
return false if hhmemb.present? && hhmemb > 8 return false if hhmemb.present? && hhmemb > max_people_with_details
return false unless all_tenants_gender_information_completed? return false unless all_tenants_gender_information_completed?
person_count = hhmemb || 8 (1..people_with_details).all? do |n|
(1..person_count).all? do |n|
public_send("age#{n}").present? && public_send("age#{n}_known").present? && public_send("age#{n}_known").zero? public_send("age#{n}").present? && public_send("age#{n}_known").present? && public_send("age#{n}_known").zero?
end end
end end
def all_tenants_gender_information_completed? def all_tenants_gender_information_completed?
return false if hhmemb.present? && hhmemb > 8 return false if hhmemb.present? && hhmemb > max_people_with_details
person_count = hhmemb || 8
(1..person_count).all? do |n| (1..people_with_details).all? do |n|
tenant_gender_information_completed?(n) tenant_gender_information_completed?(n)
end end
end end
@ -258,27 +253,21 @@ private
end end
def any_non_male_in_expected_pregnancy_age_range(min, max) def any_non_male_in_expected_pregnancy_age_range(min, max)
person_count = hhmemb || 8 (1..people_with_details).any? do |n|
(1..person_count).any? do |n|
person_in_expected_pregnancy_age_range(n, min, max) && person_is_non_male(n) person_in_expected_pregnancy_age_range(n, min, max) && person_is_non_male(n)
end end
end end
def non_males_in_the_household? def non_males_in_the_household?
person_count = hhmemb || 8 (1..people_with_details).any? do |n|
(1..person_count).any? do |n|
person_is_non_male(n) person_is_non_male(n)
end end
end end
def all_male_tenants_in_the_household? def all_male_tenants_in_the_household?
return false if hhmemb.present? && hhmemb > 8 return false if hhmemb.present? && hhmemb > max_people_with_details
person_count = hhmemb || 8 (1..people_with_details).all? do |n|
(1..person_count).all? do |n|
person_is_male(n) person_is_male(n)
end end
end end
@ -344,11 +333,7 @@ private
end end
def at_least_one_person_working_situation_is_illness? def at_least_one_person_working_situation_is_illness?
return if hhmemb.present? && hhmemb > 8 (1..people_with_details).any? { |n| public_send("ecstat#{n}") == 8 }
person_count = hhmemb || 8
(1..person_count).any? { |n| public_send("ecstat#{n}") == 8 }
end end
def no_one_in_household_with_illness? def no_one_in_household_with_illness?

2
config/locales/forms/2025/lettings/household_characteristics.en.yml

@ -7,7 +7,7 @@ en:
page_header: "" page_header: ""
check_answer_label: "Number of household members" check_answer_label: "Number of household members"
check_answer_prompt: "Enter total number of household members" check_answer_prompt: "Enter total number of household members"
hint_text: "You can provide details for a maximum of 8 people." hint_text: "You can answer up to 15 people. You will be asked to add details for a maximum of 8 people in the next questions."
question_text: "How many people live in the household for this letting?" question_text: "How many people live in the household for this letting?"
age1: age1:

2
config/locales/forms/2026/lettings/household_characteristics.en.yml

@ -7,7 +7,7 @@ en:
page_header: "" page_header: ""
check_answer_label: "Number of household members" check_answer_label: "Number of household members"
check_answer_prompt: "Enter total number of household members" check_answer_prompt: "Enter total number of household members"
hint_text: "You can provide details for a maximum of 8 people." hint_text: "You can answer up to 15 people. You will be asked to add details for a maximum of 8 people in the next questions."
question_text: "How many people live in the household for this letting?" question_text: "How many people live in the household for this letting?"
age1: age1:

29
spec/models/form/lettings/pages/person_known_spec.rb

@ -26,15 +26,12 @@ RSpec.describe Form::Lettings::Pages::PersonKnown, type: :model do
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq(
[ [{
{ "hhmemb" => 2 }, "hhmemb" => {
{ "hhmemb" => 3 }, "operator" => ">=",
{ "hhmemb" => 4 }, "operand" => 2,
{ "hhmemb" => 5 }, },
{ "hhmemb" => 6 }, }],
{ "hhmemb" => 7 },
{ "hhmemb" => 8 },
],
) )
end end
end end
@ -52,14 +49,12 @@ RSpec.describe Form::Lettings::Pages::PersonKnown, type: :model do
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq(
[ [{
{ "hhmemb" => 3 }, "hhmemb" => {
{ "hhmemb" => 4 }, "operator" => ">=",
{ "hhmemb" => 5 }, "operand" => 3,
{ "hhmemb" => 6 }, },
{ "hhmemb" => 7 }, }],
{ "hhmemb" => 8 },
],
) )
end end
end end

12
spec/models/validations/household_validations_spec.rb

@ -252,18 +252,18 @@ RSpec.describe Validations::HouseholdValidations do
record.hhmemb = 0 record.hhmemb = 0
household_validator.validate_numeric_min_max(record) household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]) expect(record.errors["hhmemb"])
.to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 8)) .to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 15))
end end
it "validates that the number of household members cannot be more than 8" do it "validates that the number of household members cannot be more than 15" do
record.hhmemb = 9 record.hhmemb = 16
household_validator.validate_numeric_min_max(record) household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]) expect(record.errors["hhmemb"])
.to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 8)) .to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 15))
end end
it "expects that the number of other household members is between the min and max" do it "expects that the number of household members is between the min and max" do
record.hhmemb = 5 record.hhmemb = 11
household_validator.validate_numeric_min_max(record) household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]).to be_empty expect(record.errors["hhmemb"]).to be_empty
end end

Loading…
Cancel
Save