Browse Source

feat: add buyer 2 value check

pull/1518/head
natdeanlewissoftwire 3 years ago
parent
commit
97893d20ad
  1. 27
      app/models/form/sales/pages/buyer2_income_max_value_check.rb
  2. 2
      app/models/form/sales/pages/buyer2_income_min_value_check.rb
  3. 2
      app/models/form/sales/subsections/household_characteristics.rb
  4. 3
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  5. 2
      app/models/form/sales/subsections/property_information.rb
  6. 18
      app/models/validations/sales/soft_validations.rb
  7. 3
      config/locales/en.yml
  8. 4
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  9. 6
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  10. 2
      spec/models/form/sales/subsections/property_information_spec.rb

27
app/models/form/sales/pages/buyer2_income_max_value_check.rb

@ -0,0 +1,27 @@
class Form::Sales::Pages::Buyer2IncomeMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [
{
"income2_over_soft_max?" => true,
},
]
@title_text = {
"translation" => "soft_validations.income.over_soft_max_for_la",
"arguments" => [
{
"key" => "field_formatted_as_currency",
"arguments_for_key" => "income2",
"i18n_template" => "income",
},
],
}
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer2IncomeValueCheck.new(nil, nil, self),
]
end
end

2
app/models/form/sales/pages/buyer2_income_value_check.rb → app/models/form/sales/pages/buyer2_income_min_value_check.rb

@ -1,4 +1,4 @@
class Form::Sales::Pages::Buyer2IncomeValueCheck < ::Form::Page class Form::Sales::Pages::Buyer2IncomeMinValueCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@header = "" @header = ""

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

@ -37,7 +37,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
buyer_2_ethnicity_nationality_pages, buyer_2_ethnicity_nationality_pages,
Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self), 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::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2),
Form::Sales::Pages::Buyer2IncomeValueCheck.new("working_situation_buyer_2_income_value_check", nil, self), Form::Sales::Pages::Buyer2IncomeMinValueCheck.new("working_situation_buyer_2_income_min_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::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::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property", nil, self, joint_purchase: false), Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property", nil, self, joint_purchase: false),

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

@ -16,7 +16,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1), Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1),
Form::Sales::Pages::Buyer2Income.new(nil, nil, self), 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::MortgageValueCheck.new("buyer_2_income_mortgage_value_check", nil, self, 2),
Form::Sales::Pages::Buyer2IncomeValueCheck.new("buyer_2_income_value_check", nil, self), 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),
Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self), Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2),
Form::Sales::Pages::HousingBenefits.new("housing_benefits_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::HousingBenefits.new("housing_benefits_joint_purchase", nil, self, joint_purchase: true),

2
app/models/form/sales/subsections/property_information.rb

@ -29,6 +29,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
Form::Sales::Pages::Address.new(nil, nil, self), Form::Sales::Pages::Address.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.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), Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self),
Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self),
] ]
end end
end end
@ -39,6 +40,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
Form::Sales::Pages::Postcode.new(nil, nil, self), Form::Sales::Pages::Postcode.new(nil, nil, self),
Form::Sales::Pages::PropertyLocalAuthority.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), Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("local_authority_buyer_1_income_max_value_check", nil, self),
Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("local_authority_buyer_2_income_max_value_check", nil, self),
] ]
end end
end end

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

@ -22,7 +22,19 @@ module Validations::Sales::SoftValidations
def income1_over_soft_max? def income1_over_soft_max?
return unless income1 && la && discounted_ownership_sale? return unless income1 && la && discounted_ownership_sale?
(london_property? && income1 > 90_000) || (property_not_in_london? && income1 > 80_000) income_over_soft_max?(income1)
end
def income2_over_soft_max?
return unless income2 && la && discounted_ownership_sale?
income_over_soft_max?(income2)
end
def combined_income_over_soft_max?
return unless income1 && income2 && la && discounted_ownership_sale?
income_over_soft_max?(income1 + income2)
end end
def staircase_bought_above_fifty? def staircase_bought_above_fifty?
@ -138,4 +150,8 @@ private
bedrooms: beds_for_la_sale_range, bedrooms: beds_for_la_sale_range,
) )
end end
def income_over_soft_max?(income)
(london_property? && income > 90_000) || (property_not_in_london? && income > 80_000)
end
end end

3
config/locales/en.yml

@ -510,7 +510,8 @@ en:
message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?"
income: income:
under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})" under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})"
over_soft_max_for_la: "You told us the income of this household is %{income}, which seems high." over_soft_max_for_la: "You told us the income of this buyer is %{income}, which seems high."
over_soft_max_for_la_combined: "You told us the income of this household is %{income}, which seems high."
rent: rent:
outside_range_title: "You told us the rent is %{brent}" outside_range_title: "You told us the rent is %{brent}"
min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}." min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}."

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

@ -49,7 +49,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
gender_2_buyer_retirement_value_check gender_2_buyer_retirement_value_check
buyer_2_working_situation buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase working_situation_2_retirement_value_check_joint_purchase
working_situation_buyer_2_income_value_check working_situation_buyer_2_income_min_value_check
buyer_2_working_situation_student_not_child_value_check buyer_2_working_situation_student_not_child_value_check
buyer_2_live_in_property buyer_2_live_in_property
number_of_others_in_property number_of_others_in_property
@ -158,7 +158,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_2_nationality buyer_2_nationality
buyer_2_working_situation buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase working_situation_2_retirement_value_check_joint_purchase
working_situation_buyer_2_income_value_check working_situation_buyer_2_income_min_value_check
buyer_2_working_situation_student_not_child_value_check buyer_2_working_situation_student_not_child_value_check
buyer_2_live_in_property buyer_2_live_in_property
number_of_others_in_property number_of_others_in_property

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

@ -28,7 +28,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_1_mortgage_value_check buyer_1_mortgage_value_check
buyer_2_income buyer_2_income
buyer_2_income_mortgage_value_check buyer_2_income_mortgage_value_check
buyer_2_income_value_check buyer_2_income_min_value_check
buyer_2_income_max_value_check
buyer_2_mortgage buyer_2_mortgage
buyer_2_mortgage_value_check buyer_2_mortgage_value_check
housing_benefits_joint_purchase housing_benefits_joint_purchase
@ -57,7 +58,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_1_mortgage_value_check buyer_1_mortgage_value_check
buyer_2_income buyer_2_income
buyer_2_income_mortgage_value_check buyer_2_income_mortgage_value_check
buyer_2_income_value_check buyer_2_income_min_value_check
buyer_2_income_max_value_check
buyer_2_mortgage buyer_2_mortgage
buyer_2_mortgage_value_check buyer_2_mortgage_value_check
housing_benefits_joint_purchase housing_benefits_joint_purchase

2
spec/models/form/sales/subsections/property_information_spec.rb

@ -28,6 +28,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
property_postcode property_postcode
property_local_authority property_local_authority
local_authority_buyer_1_income_max_value_check local_authority_buyer_1_income_max_value_check
local_authority_buyer_2_income_max_value_check
about_price_la_value_check about_price_la_value_check
property_wheelchair_accessible property_wheelchair_accessible
], ],
@ -47,6 +48,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
address address
property_local_authority property_local_authority
local_authority_buyer_1_income_max_value_check local_authority_buyer_1_income_max_value_check
local_authority_buyer_2_income_max_value_check
property_number_of_bedrooms property_number_of_bedrooms
about_price_bedrooms_value_check about_price_bedrooms_value_check
property_unit_type property_unit_type

Loading…
Cancel
Save