diff --git a/app/models/form/sales/pages/buyer1_income_max_value_check.rb b/app/models/form/sales/pages/buyer1_income_max_value_check.rb new file mode 100644 index 000000000..38f7a95aa --- /dev/null +++ b/app/models/form/sales/pages/buyer1_income_max_value_check.rb @@ -0,0 +1,27 @@ +class Form::Sales::Pages::Buyer1IncomeMaxValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @depends_on = [ + { + "income1_over_soft_max?" => true, + }, + ] + @title_text = { + "translation" => "soft_validations.income.over_soft_max_for_la", + "arguments" => [ + { + "key" => "field_formatted_as_currency", + "arguments_for_key" => "income1", + "i18n_template" => "income", + } + ], + } + @informative_text = {} + end + + def questions + @questions ||= [ + Form::Sales::Questions::Buyer1IncomeValueCheck.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/pages/buyer1_income_value_check.rb b/app/models/form/sales/pages/buyer1_income_min_value_check.rb similarity index 91% rename from app/models/form/sales/pages/buyer1_income_value_check.rb rename to app/models/form/sales/pages/buyer1_income_min_value_check.rb index 48d8f5fff..08ec83d08 100644 --- a/app/models/form/sales/pages/buyer1_income_value_check.rb +++ b/app/models/form/sales/pages/buyer1_income_min_value_check.rb @@ -1,4 +1,4 @@ -class Form::Sales::Pages::Buyer1IncomeValueCheck < ::Form::Page +class Form::Sales::Pages::Buyer1IncomeMinValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @depends_on = [ diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 922d95edd..af85130b4 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -24,7 +24,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Nationality1.new(nil, nil, self), 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::Buyer1IncomeValueCheck.new("working_situation_buyer_1_income_value_check", nil, self), + Form::Sales::Pages::Buyer1IncomeMinValueCheck.new("working_situation_buyer_1_income_min_value_check", nil, self), Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_relationship_student_not_child_value_check", nil, self, person_index: 2), diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index 502b87fc9..293c11657 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -9,7 +9,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection def pages @pages ||= [ Form::Sales::Pages::Buyer1Income.new(nil, nil, self), - Form::Sales::Pages::Buyer1IncomeValueCheck.new("buyer_1_income_value_check", 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), 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), diff --git a/app/models/form/sales/subsections/property_information.rb b/app/models/form/sales/subsections/property_information.rb index cca34a764..ea4b51deb 100644 --- a/app/models/form/sales/subsections/property_information.rb +++ b/app/models/form/sales/subsections/property_information.rb @@ -28,6 +28,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection 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), ] end end @@ -37,6 +38,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection [ Form::Sales::Pages::Postcode.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), ] end end diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index d72118d05..e439c7369 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -19,6 +19,12 @@ module Validations::Sales::SoftValidations income2 < ALLOWED_INCOME_RANGES_SALES[ecstat2][:soft_min] end + def income1_over_soft_max? + return unless income1 && la && discounted_ownership_sale? + + (london_property? && income1 > 90_000) || (property_not_in_london? && income1 > 80_000) + end + def staircase_bought_above_fifty? stairbought && stairbought > 50 end diff --git a/config/locales/en.yml b/config/locales/en.yml index bcfe32f46..c44fadb8a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -505,6 +505,7 @@ en: message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" income: 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." rent: 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}." diff --git a/spec/models/form/sales/pages/buyer1_income_value_check_spec.rb b/spec/models/form/sales/pages/buyer1_income_min_value_check_spec.rb similarity index 78% rename from spec/models/form/sales/pages/buyer1_income_value_check_spec.rb rename to spec/models/form/sales/pages/buyer1_income_min_value_check_spec.rb index f770bd651..19dfae001 100644 --- a/spec/models/form/sales/pages/buyer1_income_value_check_spec.rb +++ b/spec/models/form/sales/pages/buyer1_income_min_value_check_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" -RSpec.describe Form::Sales::Pages::Buyer1IncomeValueCheck, type: :model do +RSpec.describe Form::Sales::Pages::Buyer1IncomeMinValueCheck, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection) } - let(:page_id) { "prefix_buyer_1_income_value_check" } + let(:page_id) { "prefix_buyer_1_income_min_value_check" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } @@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Pages::Buyer1IncomeValueCheck, type: :model do end it "has the correct id" do - expect(page.id).to eq("prefix_buyer_1_income_value_check") + expect(page.id).to eq("prefix_buyer_1_income_min_value_check") end it "has the correct header" do diff --git a/spec/models/form/sales/questions/buyer1_income_value_check_spec.rb b/spec/models/form/sales/questions/buyer1_income_min_value_check_spec.rb similarity index 94% rename from spec/models/form/sales/questions/buyer1_income_value_check_spec.rb rename to spec/models/form/sales/questions/buyer1_income_min_value_check_spec.rb index 89801a398..446176f7c 100644 --- a/spec/models/form/sales/questions/buyer1_income_value_check_spec.rb +++ b/spec/models/form/sales/questions/buyer1_income_min_value_check_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Questions::Buyer1IncomeValueCheck, type: :model do +RSpec.describe Form::Sales::Questions::Buyer1IncomeMinValueCheck, type: :model do subject(:question) { described_class.new(question_id, question_definition, page) } let(:question_id) { nil } diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 57a9ce019..1277749ef 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -37,7 +37,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_value_check + working_situation_buyer_1_income_min_value_check buyer_1_live_in_property buyer_2_relationship_to_buyer_1 buyer_2_relationship_student_not_child_value_check @@ -139,7 +139,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_value_check + working_situation_buyer_1_income_min_value_check buyer_1_live_in_property buyer_2_relationship_to_buyer_1 buyer_2_relationship_student_not_child_value_check diff --git a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb index aef451878..ee5700994 100644 --- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb +++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model expect(subsection.pages.compact.map(&:id)).to eq( %w[ buyer_1_income - buyer_1_income_value_check + buyer_1_income_min_value_check buyer_1_income_mortgage_value_check buyer_1_mortgage buyer_1_mortgage_value_check @@ -49,7 +49,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model expect(subsection.pages.map(&:id)).to eq( %w[ buyer_1_income - buyer_1_income_value_check + buyer_1_income_min_value_check buyer_1_income_mortgage_value_check buyer_1_mortgage buyer_1_mortgage_value_check