Browse Source

Combine min and max checks for income based on ecstat

pull/2779/head
Rachael Booth 6 months ago
parent
commit
d0f6388365
  1. 2
      app/models/form/sales/pages/buyer1_income_discounted_max_value_check.rb
  2. 36
      app/models/form/sales/pages/buyer1_income_ecstat_max_value_check.rb
  3. 18
      app/models/form/sales/pages/buyer1_income_ecstat_value_check.rb
  4. 2
      app/models/form/sales/pages/buyer2_income_discounted_max_value_check.rb
  5. 36
      app/models/form/sales/pages/buyer2_income_ecstat_max_value_check.rb
  6. 18
      app/models/form/sales/pages/buyer2_income_ecstat_value_check.rb
  7. 6
      app/models/form/sales/subsections/household_characteristics.rb
  8. 6
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  9. 42
      app/models/validations/sales/soft_validations.rb
  10. 18
      config/locales/forms/2023/sales/soft_validations.en.yml
  11. 22
      config/locales/forms/2024/sales/soft_validations.en.yml
  12. 34
      config/locales/forms/2025/sales/soft_validations.en.yml
  13. 14
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  14. 10
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

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

@ -6,7 +6,7 @@ class Form::Sales::Pages::Buyer1IncomeDiscountedMaxValueCheck < ::Form::Page
"income1_over_soft_max_for_discounted_ownership?" => true,
},
]
@copy_key = "sales.soft_validations.income1_value_check.max.discounted"
@copy_key = "sales.soft_validations.income1_value_check.discounted"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [

36
app/models/form/sales/pages/buyer1_income_ecstat_max_value_check.rb

@ -1,36 +0,0 @@
class Form::Sales::Pages::Buyer1IncomeEcstatMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection, check_answers_card_number:)
super(id, hsh, subsection)
@depends_on = [
{
"income1_over_soft_max_for_ecstat?" => true,
},
]
@copy_key = "sales.soft_validations.income1_value_check.max.ecstat"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
{
"key" => "field_formatted_as_currency",
"arguments_for_key" => "income1",
"i18n_template" => "income",
},
],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
@check_answers_card_number = check_answers_card_number
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1IncomeValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number),
]
end
def interruption_screen_question_ids
%w[ecstat1 income1]
end
end

18
app/models/form/sales/pages/buyer1_income_min_value_check.rb → app/models/form/sales/pages/buyer1_income_ecstat_value_check.rb

@ -1,12 +1,12 @@
class Form::Sales::Pages::Buyer1IncomeMinValueCheck < ::Form::Page
class Form::Sales::Pages::Buyer1IncomeEcstatValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{
"income1_under_soft_min?" => true,
"income1_out_of_soft_range?" => true,
},
]
@copy_key = "sales.soft_validations.income1_value_check.min"
@copy_key = "sales.soft_validations.income1_value_check.ecstat"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
@ -15,16 +15,16 @@ class Form::Sales::Pages::Buyer1IncomeMinValueCheck < ::Form::Page
"arguments_for_key" => "income1",
"i18n_template" => "income",
},
{
"key" => "income_soft_min_for_ecstat",
"arguments_for_key" => "ecstat1",
"i18n_template" => "minimum",
},
],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
"arguments" => [
{
"key" => "income1_more_or_less_text",
"i18n_template" => "more_or_less",
},
],
}
end

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

@ -6,7 +6,7 @@ class Form::Sales::Pages::Buyer2IncomeDiscountedMaxValueCheck < ::Form::Page
"income2_over_soft_max_for_discounted_ownership?" => true,
},
]
@copy_key = "sales.soft_validations.income2_value_check.max.discounted"
@copy_key = "sales.soft_validations.income2_value_check.discounted"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [

36
app/models/form/sales/pages/buyer2_income_ecstat_max_value_check.rb

@ -1,36 +0,0 @@
class Form::Sales::Pages::Buyer2IncomeEcstatMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection, check_answers_card_number:)
super(id, hsh, subsection)
@depends_on = [
{
"income2_over_soft_max_for_ecstat?" => true,
},
]
@copy_key = "sales.soft_validations.income2_value_check.max.ecstat"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
{
"key" => "field_formatted_as_currency",
"arguments_for_key" => "income2",
"i18n_template" => "income",
},
],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
@check_answers_card_number = check_answers_card_number
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer2IncomeValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number),
]
end
def interruption_screen_question_ids
%w[ecstat2 income2]
end
end

18
app/models/form/sales/pages/buyer2_income_min_value_check.rb → app/models/form/sales/pages/buyer2_income_ecstat_value_check.rb

@ -1,12 +1,12 @@
class Form::Sales::Pages::Buyer2IncomeMinValueCheck < ::Form::Page
class Form::Sales::Pages::Buyer2IncomeEcstatValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{
"income2_under_soft_min?" => true,
"income2_out_of_soft_range?" => true,
},
]
@copy_key = "sales.soft_validations.income2_value_check.min"
@copy_key = "sales.soft_validations.income2_value_check.ecstat"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
@ -15,16 +15,16 @@ class Form::Sales::Pages::Buyer2IncomeMinValueCheck < ::Form::Page
"arguments_for_key" => "income2",
"i18n_template" => "income",
},
{
"key" => "income_soft_min_for_ecstat",
"arguments_for_key" => "ecstat2",
"i18n_template" => "minimum",
},
],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
"arguments" => [
{
"key" => "income2_more_or_less_text",
"i18n_template" => "more_or_less",
},
],
}
end

6
app/models/form/sales/subsections/household_characteristics.rb

@ -35,8 +35,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Buyer1WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_1_retirement_value_check", nil, self, person_index: 1),
(Form::Sales::Pages::NotRetiredValueCheck.new("working_situation_1_not_retired_value_check", nil, self, person_index: 1) if form.start_year_2024_or_later?),
Form::Sales::Pages::Buyer1IncomeMinValueCheck.new("working_situation_buyer_1_income_min_value_check", nil, self),
(Form::Sales::Pages::Buyer1IncomeEcstatMaxValueCheck.new("working_situation_buyer_1_income_max_value_check", nil, self, check_answers_card_number: 1) if form.start_year_2025_or_later?),
Form::Sales::Pages::Buyer1IncomeEcstatValueCheck.new("working_situation_buyer_1_income_value_check", nil, self),
Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::BuyerLiveInValueCheck.new("buyer_1_live_in_property_value_check", nil, self, person_index: 1),
(form.start_year_2025_or_later? ? Form::Sales::Pages::Buyer2RelationshipToBuyer1YesNo.new(nil, nil, self) : Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self)),
@ -52,8 +51,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2),
(Form::Sales::Pages::NotRetiredValueCheck.new("working_situation_2_not_retired_value_check_joint_purchase", nil, self, person_index: 2) if form.start_year_2024_or_later?),
Form::Sales::Pages::Buyer2IncomeMinValueCheck.new("working_situation_buyer_2_income_min_value_check", nil, self),
(Form::Sales::Pages::Buyer2IncomeEcstatMaxValueCheck.new("working_situation_buyer_2_income_max_value_check", nil, self, check_answers_card_number: 2) if form.start_year_2025_or_later?),
Form::Sales::Pages::Buyer2IncomeEcstatValueCheck.new("working_situation_buyer_2_income_value_check", nil, self),
Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_working_situation_student_not_child_value_check", nil, self, person_index: 2),
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::BuyerLiveInValueCheck.new("buyer_2_live_in_property_value_check", nil, self, person_index: 2),

6
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -16,8 +16,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::Buyer1Income.new(nil, nil, self),
Form::Sales::Pages::Buyer1IncomeMinValueCheck.new("buyer_1_income_min_value_check", nil, self),
(Form::Sales::Pages::Buyer1IncomeEcstatMaxValueCheck.new("buyer_1_income_ecstat_max_value_check", nil, self, check_answers_card_number: 1) if form.start_year_2025_or_later?),
Form::Sales::Pages::Buyer1IncomeEcstatValueCheck.new("buyer_1_income_ecstat_value_check", nil, self),
Form::Sales::Pages::Buyer1IncomeDiscountedMaxValueCheck.new("buyer_1_income_discounted_max_value_check", nil, self, check_answers_card_number: 1),
Form::Sales::Pages::CombinedIncomeMaxValueCheck.new("buyer_1_combined_income_max_value_check", nil, self, check_answers_card_number: 1),
Form::Sales::Pages::MortgageValueCheck.new("buyer_1_income_mortgage_value_check", nil, self, 1),
@ -25,8 +24,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1),
Form::Sales::Pages::Buyer2Income.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_income_mortgage_value_check", nil, self, 2),
Form::Sales::Pages::Buyer2IncomeMinValueCheck.new("buyer_2_income_min_value_check", nil, self),
(Form::Sales::Pages::Buyer2IncomeEcstatMaxValueCheck.new("buyer_2_income_ecstat_max_value_check", nil, self, check_answers_card_number: 2) if form.start_year_2025_or_later?),
Form::Sales::Pages::Buyer2IncomeEcstatValueCheck.new("buyer_2_income_ecstat_value_check", nil, self),
Form::Sales::Pages::Buyer2IncomeDiscountedMaxValueCheck.new("buyer_2_income_discounted_max_value_check", nil, self, check_answers_card_number: 2),
Form::Sales::Pages::CombinedIncomeMaxValueCheck.new("buyer_2_combined_income_max_value_check", nil, self, check_answers_card_number: 2),
Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self),

42
app/models/validations/sales/soft_validations.rb

@ -23,12 +23,20 @@ module Validations::Sales::SoftValidations
},
}.freeze
def income1_under_soft_min?
income_under_soft_min?(income1, ecstat1)
def income1_outside_soft_range_for_ecstat?
income1_under_soft_min? || income1_over_soft_max_for_ecstat?
end
def income2_under_soft_min?
income_under_soft_min?(income2, ecstat2)
def income1_more_or_less_text
income1_under_soft_min? ? "less" : "more"
end
def income2_outside_soft_range_for_ecstat?
income2_under_soft_min? || income2_over_soft_max_for_ecstat?
end
def income2_more_or_less_text
income2_under_soft_min? ? "less" : "more"
end
def income1_over_soft_max_for_discounted_ownership?
@ -37,20 +45,12 @@ module Validations::Sales::SoftValidations
income_over_discounted_sale_soft_max?(income1)
end
def income1_over_soft_max_for_ecstat?
income_over_soft_max?(income1, ecstat1)
end
def income2_over_soft_max_for_discounted_ownership?
return unless income2 && la && discounted_ownership_sale?
income_over_discounted_sale_soft_max?(income2)
end
def income2_over_soft_max_for_ecstat?
income_over_soft_max?(income2, ecstat2)
end
def combined_income_over_soft_max_for_discounted_ownership?
return unless income1 && income2 && la && discounted_ownership_sale?
@ -210,6 +210,14 @@ private
)
end
def income1_under_soft_min?
income_under_soft_min?(income1, ecstat1)
end
def income2_under_soft_min?
income_under_soft_min?(income2, ecstat2)
end
def income_under_soft_min?(income, ecstat)
return unless income && ecstat
@ -219,9 +227,19 @@ private
income < income_ranges[ecstat][:soft_min]
end
def income1_over_soft_max_for_ecstat?
income_over_soft_max?(income1, ecstat1)
end
def income2_over_soft_max_for_ecstat?
income_over_soft_max?(income2, ecstat2)
end
def income_over_soft_max?(income, ecstat)
return unless income && ecstat && form.start_year_2025_or_later?
return false unless ALLOWED_INCOME_RANGES_SALES[2025][ecstat]
income > ALLOWED_INCOME_RANGES_SALES[2025][ecstat][:soft_max]
end

18
config/locales/forms/2023/sales/soft_validations.en.yml

@ -33,27 +33,25 @@ en:
check_answer_label: "Buyer 1 income confirmation"
hint_text: ""
question_text: "Are you sure this is correct?"
min:
ecstat:
page_header: ""
title_text: "You told us income was %{income}."
informative_text: "This is less than we would expect for someone in this working situation."
max:
discounted:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}. This seems high. Are you sure this is correct?"
discounted:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}. This seems high. Are you sure this is correct?"
income2_value_check:
check_answer_label: "Buyer 2 income confirmation"
hint_text: ""
question_text: "Are you sure this is correct?"
min:
ecstat:
page_header: ""
title_text: "You told us income was %{income}."
informative_text: "This is less than we would expect for someone in this working situation."
max:
discounted:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}. This seems high. Are you sure this is correct?"
discounted:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}. This seems high. Are you sure this is correct?"
combined_income_value_check:
page_header: ""

22
config/locales/forms/2024/sales/soft_validations.en.yml

@ -31,27 +31,25 @@ en:
check_answer_label: "Buyer 1 income confirmation"
hint_text: ""
question_text: "Are you sure this is correct?"
min:
ecstat:
page_header: ""
title_text: "You told us income was %{income}."
informative_text: "This is less than we would expect for someone in this working situation."
max:
discounted:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}. This seems high. Are you sure this is correct?"
informative_text: "This is %{more_or_less} than we would expect for someone in this working situation."
discounted:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}. This seems high. Are you sure this is correct?"
income2_value_check:
check_answer_label: "Buyer 2 income confirmation"
hint_text: ""
question_text: "Are you sure this is correct?"
min:
ecstat:
page_header: ""
title_text: "You told us income was %{income}."
informative_text: "This is less than we would expect for someone in this working situation."
max:
discounted:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}. This seems high. Are you sure this is correct?"
informative_text: "This is %{more_or_less} than we would expect for someone in this working situation."
discounted:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}. This seems high. Are you sure this is correct?"
combined_income_value_check:
page_header: ""

34
config/locales/forms/2025/sales/soft_validations.en.yml

@ -31,35 +31,25 @@ en:
check_answer_label: "Buyer 1 income confirmation"
hint_text: ""
question_text: "Are you sure this is correct?"
min:
ecstat:
page_header: ""
title_text: "You told us income was %{income}."
informative_text: "This is less than we would expect for someone in this working situation."
max:
discounted:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}. This seems high for this sale type. Are you sure this is correct?"
ecstat:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}."
informative_text: "This is more than we would expect for someone in this working situation."
title_text: "You told us the income of buyer 1 is %{income}."
informative_text: "This is %{more_or_less} than we would expect for someone in this working situation."
discounted:
page_header: ""
title_text: "You told us the income of buyer 1 is %{income}. This seems high for this sale type. Are you sure this is correct?"
income2_value_check:
check_answer_label: "Buyer 2 income confirmation"
hint_text: ""
question_text: "Are you sure this is correct?"
min:
ecstat:
page_header: ""
title_text: "You told us income was %{income}."
informative_text: "This is less than we would expect for someone in this working situation."
max:
discounted:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}. This seems high for this sale type. Are you sure this is correct?"
ecstat:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}."
informative_text: "This is more than we would expect for someone in this working situation."
title_text: "You told us the income of buyer 2 is %{income}."
informative_text: "This is %{more_or_less} than we would expect for someone in this working situation."
discounted:
page_header: ""
title_text: "You told us the income of buyer 2 is %{income}. This seems high for this sale type. Are you sure this is correct?"
combined_income_value_check:
page_header: ""

14
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -44,7 +44,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_nationality
buyer_1_working_situation
working_situation_1_retirement_value_check
working_situation_buyer_1_income_min_value_check
working_situation_buyer_1_income_value_check
buyer_1_live_in_property
buyer_1_live_in_property_value_check
buyer_2_relationship_to_buyer_1
@ -64,7 +64,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_2_nationality
buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase
working_situation_buyer_2_income_min_value_check
working_situation_buyer_2_income_value_check
buyer_2_working_situation_student_not_child_value_check
buyer_2_live_in_property
buyer_2_live_in_property_value_check
@ -171,7 +171,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_working_situation
working_situation_1_retirement_value_check
working_situation_1_not_retired_value_check
working_situation_buyer_1_income_min_value_check
working_situation_buyer_1_income_value_check
buyer_1_live_in_property
buyer_1_live_in_property_value_check
buyer_2_relationship_to_buyer_1
@ -193,7 +193,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase
working_situation_2_not_retired_value_check_joint_purchase
working_situation_buyer_2_income_min_value_check
working_situation_buyer_2_income_value_check
buyer_2_working_situation_student_not_child_value_check
buyer_2_live_in_property
buyer_2_live_in_property_value_check
@ -305,8 +305,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_working_situation
working_situation_1_retirement_value_check
working_situation_1_not_retired_value_check
working_situation_buyer_1_income_min_value_check
working_situation_buyer_1_income_max_value_check
working_situation_buyer_1_income_value_check
buyer_1_live_in_property
buyer_1_live_in_property_value_check
buyer_2_relationship_to_buyer_1
@ -328,8 +327,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase
working_situation_2_not_retired_value_check_joint_purchase
working_situation_buyer_2_income_min_value_check
working_situation_buyer_2_income_max_value_check
working_situation_buyer_2_income_value_check
buyer_2_working_situation_student_not_child_value_check
buyer_2_live_in_property
buyer_2_live_in_property_value_check

10
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -27,7 +27,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.pages.map(&:id)).to eq(
%w[
buyer_1_income
buyer_1_income_min_value_check
buyer_1_income_ecstat_value_check
buyer_1_income_discounted_max_value_check
buyer_1_combined_income_max_value_check
buyer_1_income_mortgage_value_check
@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_1_mortgage_value_check
buyer_2_income
buyer_2_income_mortgage_value_check
buyer_2_income_min_value_check
buyer_2_income_ecstat_value_check
buyer_2_income_discounted_max_value_check
buyer_2_combined_income_max_value_check
buyer_2_mortgage
@ -67,8 +67,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.pages.map(&:id)).to eq(
%w[
buyer_1_income
buyer_1_income_min_value_check
buyer_1_income_ecstat_max_value_check
buyer_1_income_ecstat_value_check
buyer_1_income_discounted_max_value_check
buyer_1_combined_income_max_value_check
buyer_1_income_mortgage_value_check
@ -76,8 +75,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_1_mortgage_value_check
buyer_2_income
buyer_2_income_mortgage_value_check
buyer_2_income_min_value_check
buyer_2_income_ecstat_max_value_check
buyer_2_income_ecstat_value_check
buyer_2_income_discounted_max_value_check
buyer_2_combined_income_max_value_check
buyer_2_mortgage

Loading…
Cancel
Save