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)
return unless hhmemb
(2..hhmemb).each do |i|
(2..people_with_details).each do |i|
next if i == partner_number
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:)
super(id, hsh, subsection)
@id = "person_#{person_index}_known"
@depends_on = (person_index..8).map { |index| { "hhmemb" => index } }
@person_index = person_index
@depends_on = depends_on
end
def questions
@questions ||= [Form::Lettings::Questions::DetailsKnown.new(nil, nil, self, person_index: @person_index)]
end
def depends_on
[{ "hhmemb" => {
"operator" => ">=",
"operand" => @person_index,
} }]
end
end

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

@ -5,7 +5,7 @@ class Form::Lettings::Questions::Hhmemb < ::Form::Question
@type = "numeric"
@width = 2
@check_answers_card_number = 0
@max = 8
@max = 15
@min = 1
@step = 1
@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
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
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 = {
social_rent: 0,
affordable_rent: 1,
@ -284,7 +285,7 @@ class LettingsLog < Log
range = ALLOWED_INCOME_RANGES[ecstat1].clone
if hhmemb > 1
(2..hhmemb).each do |person_index|
(2..people_with_details).each do |person_index|
ecstat = self["ecstat#{person_index}"]
if ecstat.nil?

8
app/models/log.rb

@ -204,6 +204,14 @@ class Log < ApplicationRecord
false
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?
ethnic_group == 17
end

1
app/models/sales_log.rb

@ -104,6 +104,7 @@ class SalesLog < Log
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
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?
false

4
app/models/validations/financial_validations.rb

@ -41,7 +41,7 @@ module Validations::FinancialValidations
:over_hard_max,
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(
"ecstat#{n}",
:over_hard_max,
@ -70,7 +70,7 @@ module Validations::FinancialValidations
:under_hard_min,
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(
"ecstat#{n}",
:under_hard_min,

35
app/models/validations/soft_validations.rb

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

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

@ -7,7 +7,7 @@ en:
page_header: ""
check_answer_label: "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?"
age1:

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

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

12
spec/models/validations/household_validations_spec.rb

@ -252,18 +252,18 @@ RSpec.describe Validations::HouseholdValidations do
record.hhmemb = 0
household_validator.validate_numeric_min_max(record)
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
it "validates that the number of household members cannot be more than 8" do
record.hhmemb = 9
it "validates that the number of household members cannot be more than 15" do
record.hhmemb = 16
household_validator.validate_numeric_min_max(record)
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
it "expects that the number of other household members is between the min and max" do
record.hhmemb = 5
it "expects that the number of household members is between the min and max" do
record.hhmemb = 11
household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]).to be_empty
end

Loading…
Cancel
Save