Skip to content

Commit

Permalink
CLDC-3753: Update soft income validations (#2779)
Browse files Browse the repository at this point in the history
* CLDC-3753: Update soft income validations

* Update tests

* Fix linting

* Include reference to informative text translations copy

* Combine min and max checks for income based on ecstat

* Fixes

* Update tests
  • Loading branch information
RachaelBooth authored Nov 28, 2024
1 parent 4157a7b commit b3dca51
Show file tree
Hide file tree
Showing 21 changed files with 437 additions and 366 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class Form::Sales::Pages::Buyer1IncomeMaxValueCheck < ::Form::Page
class Form::Sales::Pages::Buyer1IncomeDiscountedMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection, check_answers_card_number:)
super(id, hsh, subsection)
@depends_on = [
{
"income1_over_soft_max?" => true,
"income1_over_soft_max_for_discounted_ownership?" => true,
},
]
@copy_key = "sales.soft_validations.income1_value_check.max"
@copy_key = "sales.soft_validations.income1_value_check.discounted"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
Expand Down
Original file line number Diff line number Diff line change
@@ -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_outside_soft_range_for_ecstat?" => 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" => [
Expand All @@ -15,16 +15,16 @@ def initialize(id, hsh, subsection)
"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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class Form::Sales::Pages::Buyer2IncomeMaxValueCheck < ::Form::Page
class Form::Sales::Pages::Buyer2IncomeDiscountedMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection, check_answers_card_number:)
super(id, hsh, subsection)
@depends_on = [
{
"income2_over_soft_max?" => true,
"income2_over_soft_max_for_discounted_ownership?" => true,
},
]
@copy_key = "sales.soft_validations.income2_value_check.max"
@copy_key = "sales.soft_validations.income2_value_check.discounted"
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [
Expand Down
Original file line number Diff line number Diff line change
@@ -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_outside_soft_range_for_ecstat?" => 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" => [
Expand All @@ -15,16 +15,16 @@ def initialize(id, hsh, subsection)
"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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def initialize(id, hsh, subsection, check_answers_card_number:)
super(id, hsh, subsection)
@depends_on = [
{
"combined_income_over_soft_max?" => true,
"combined_income_over_soft_max_for_discounted_ownership?" => true,
},
]
@copy_key = "sales.soft_validations.combined_income_value_check"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def pages
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::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)),
Expand All @@ -51,7 +51,7 @@ def pages
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::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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def depends_on
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::Buyer1IncomeMaxValueCheck.new("buyer_1_income_max_value_check", nil, self, check_answers_card_number: 1),
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),
Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self),
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::Buyer2IncomeMaxValueCheck.new("buyer_2_income_max_value_check", nil, self, check_answers_card_number: 2),
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),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2),
Expand Down
8 changes: 4 additions & 4 deletions app/models/form/sales/subsections/property_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def uprn_questions
Form::Sales::Pages::UprnSelection.new(nil, nil, self),
Form::Sales::Pages::AddressFallback.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self),
Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::Buyer1IncomeDiscountedMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::Buyer2IncomeDiscountedMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::CombinedIncomeMaxValueCheck.new("local_authority_combined_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::AboutPriceValueCheck.new("about_price_la_value_check", nil, self),
]
Expand All @@ -42,8 +42,8 @@ def uprn_questions
Form::Sales::Pages::UprnConfirmation.new(nil, nil, self),
Form::Sales::Pages::Address.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self),
Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::Buyer1IncomeDiscountedMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::Buyer2IncomeDiscountedMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::CombinedIncomeMaxValueCheck.new("local_authority_combined_income_max_value_check", nil, self, check_answers_card_number: nil),
Form::Sales::Pages::AboutPriceValueCheck.new("about_price_la_value_check", nil, self),
]
Expand Down
87 changes: 69 additions & 18 deletions app/models/validations/sales/soft_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,59 @@ module Validations::Sales::SoftValidations
include Validations::Sales::SaleInformationValidations

ALLOWED_INCOME_RANGES_SALES = {
1 => OpenStruct.new(soft_min: 5000),
2 => OpenStruct.new(soft_min: 1500),
3 => OpenStruct.new(soft_min: 1000),
5 => OpenStruct.new(soft_min: 2000),
0 => OpenStruct.new(soft_min: 2000),
2024 => {
1 => OpenStruct.new(soft_min: 5000),
2 => OpenStruct.new(soft_min: 1500),
3 => OpenStruct.new(soft_min: 1000),
5 => OpenStruct.new(soft_min: 2000),
0 => OpenStruct.new(soft_min: 2000),
},
2025 => {
1 => OpenStruct.new(soft_min: 13_400, soft_max: 150_000),
2 => OpenStruct.new(soft_min: 2_600, soft_max: 80_000),
3 => OpenStruct.new(soft_min: 2_080, soft_max: 30_000),
4 => OpenStruct.new(soft_min: 520, soft_max: 23_400),
5 => OpenStruct.new(soft_min: 520, soft_max: 80_000),
6 => OpenStruct.new(soft_min: 520, soft_max: 50_000),
7 => OpenStruct.new(soft_min: 520, soft_max: 30_000),
8 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
9 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
0 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
},
}.freeze

def income1_under_soft_min?
return false unless ecstat1 && income1 && ALLOWED_INCOME_RANGES_SALES[ecstat1]
def income1_outside_soft_range_for_ecstat?
income1_under_soft_min? || income1_over_soft_max_for_ecstat?
end

income1 < ALLOWED_INCOME_RANGES_SALES[ecstat1][:soft_min]
def income1_more_or_less_text
income1_under_soft_min? ? "less" : "more"
end

def income2_under_soft_min?
return false unless ecstat2 && income2 && ALLOWED_INCOME_RANGES_SALES[ecstat2]
def income2_outside_soft_range_for_ecstat?
income2_under_soft_min? || income2_over_soft_max_for_ecstat?
end

income2 < ALLOWED_INCOME_RANGES_SALES[ecstat2][:soft_min]
def income2_more_or_less_text
income2_under_soft_min? ? "less" : "more"
end

def income1_over_soft_max?
def income1_over_soft_max_for_discounted_ownership?
return unless income1 && la && discounted_ownership_sale?

income_over_soft_max?(income1)
income_over_discounted_sale_soft_max?(income1)
end

def income2_over_soft_max?
def income2_over_soft_max_for_discounted_ownership?
return unless income2 && la && discounted_ownership_sale?

income_over_soft_max?(income2)
income_over_discounted_sale_soft_max?(income2)
end

def combined_income_over_soft_max?
def combined_income_over_soft_max_for_discounted_ownership?
return unless income1 && income2 && la && discounted_ownership_sale?

income_over_soft_max?(income1 + income2)
income_over_discounted_sale_soft_max?(income1 + income2)
end

def staircase_bought_above_fifty?
Expand Down Expand Up @@ -192,7 +210,40 @@ def sale_range
)
end

def income_over_soft_max?(income)
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

income_ranges = form.start_year_2025_or_later? ? ALLOWED_INCOME_RANGES_SALES[2025] : ALLOWED_INCOME_RANGES_SALES[2024]
return false unless income_ranges[ecstat]

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

def income_over_discounted_sale_soft_max?(income)
(london_property? && income > 90_000) || (property_not_in_london? && income > 80_000)
end
end
Loading

0 comments on commit b3dca51

Please sign in to comment.