Browse Source

CLDC-853 Added hard validations for sales income2

pull/1101/head
David May-Miller 4 years ago committed by Arthur Campbell
parent
commit
8962b66f35
  1. 1
      app/models/form/sales/questions/buyer2_income.rb
  2. 25
      app/models/validations/sales/financial_validations.rb
  3. 4
      app/models/validations/sales/household_validations.rb
  4. 8
      app/models/validations/shared_validations.rb
  5. 4
      config/locales/en.yml
  6. 4
      spec/models/validations/sales/financial_validations_spec.rb

1
app/models/form/sales/questions/buyer2_income.rb

@ -7,6 +7,7 @@ class Form::Sales::Questions::Buyer2Income < ::Form::Question
@type = "numeric" @type = "numeric"
@hint_text = "Provide the gross annual income (i.e. salary before tax) plus the annual amount of benefits, Universal Credit or pensions, and income from investments." @hint_text = "Provide the gross annual income (i.e. salary before tax) plus the annual amount of benefits, Universal Credit or pensions, and income from investments."
@min = 0 @min = 0
@max = 999_999
@step = 1 @step = 1
@width = 5 @width = 5
@prefix = "£" @prefix = "£"

25
app/models/validations/sales/financial_validations.rb

@ -18,6 +18,13 @@ module Validations::Sales::FinancialValidations
record.errors.add :postcode_full, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) if record.income1 > 80_000 record.errors.add :postcode_full, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) if record.income1 > 80_000
end end
end end
if record.income1 && record.income2
if record.london_property?
record.errors.add :income1, I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 90_000) if record.income1 + record.income2 > 90_000
elsif record.income1 + record.income2 > 80_000
record.errors.add :income1, I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 80_000)
end
end end
def validate_cash_discount(record) def validate_cash_discount(record)
@ -43,5 +50,23 @@ module Validations::Sales::FinancialValidations
record.errors.add :stairowned, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75") record.errors.add :stairowned, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75")
record.errors.add :type, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75") record.errors.add :type, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75")
end end
def validate_income2(record)
if record.ecstat2 && record.income2 && record.ownershipsch == 1
if record.london_property?
record.errors.add :income2, I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000) if record.income2 > 90_000
elsif record.income2 > 80_000
record.errors.add :income2, I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)
end
end
if record.income1 && record.income2
if record.london_property?
record.errors.add :income2, I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 90_000) if record.income1 + record.income2 > 90_000
elsif record.income1 + record.income2 > 80_000
record.errors.add :income2, I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 80_000)
end
end
child_income_validation(record, :income2)
end end
end end

4
app/models/validations/sales/household_validations.rb

@ -19,6 +19,10 @@ module Validations::Sales::HouseholdValidations
end end
end end
def validate_relat2(record)
child_income_validation(record, :relat2)
end
private private
def validate_person_age_matches_relationship(record, person_num) def validate_person_age_matches_relationship(record, person_num)

8
app/models/validations/shared_validations.rb

@ -108,6 +108,14 @@ module Validations::SharedValidations
end end
end end
def child_income_validation(record, field)
if record.relat2 && record.income2
if record.relat2 == "C" && record.income2 > 0
record.errors.add field, I18n.t("validations.financial.income.child_has_income")
end
end
end
private private
def person_is_partner?(relationship) def person_is_partner?(relationship)

4
config/locales/en.yml

@ -216,8 +216,10 @@ en:
under_hard_min: "Net income cannot be less than £%{hard_min} per week given the tenant’s working situation" under_hard_min: "Net income cannot be less than £%{hard_min} per week given the tenant’s working situation"
freq_missing: "Select how often the household receives income" freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total" earnings_missing: "Enter how much income the household has in total"
income1: income:
over_hard_max: "Income must be lower than £%{hard_max}" over_hard_max: "Income must be lower than £%{hard_max}"
combined_over_hard_max: "Combined income must not be more than £%{hard_max}"
child_has_income: "A child's income must be 0"
negative_currency: "Enter an amount above 0" negative_currency: "Enter an amount above 0"
rent: rent:
less_than_shortfall: "Enter an amount that is more than the shortfall in basic rent" less_than_shortfall: "Enter an amount that is more than the shortfall in basic rent"

4
spec/models/validations/sales/financial_validations_spec.rb

@ -17,6 +17,8 @@ RSpec.describe Validations::Sales::FinancialValidations do
financial_validator.validate_income1(record) financial_validator.validate_income1(record)
expect(record.errors["income1"]) expect(record.errors["income1"])
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000))
expect(record.errors["income1"])
.to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000))
expect(record.errors["ecstat1"]) expect(record.errors["ecstat1"])
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000))
expect(record.errors["ownershipsch"]) expect(record.errors["ownershipsch"])
@ -51,6 +53,8 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.income1 = 95_000 record.income1 = 95_000
record.ecstat1 = ecstat record.ecstat1 = ecstat
financial_validator.validate_income1(record) financial_validator.validate_income1(record)
expect(record.errors["income1"])
.to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000))
expect(record.errors["income1"]) expect(record.errors["income1"])
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000))
expect(record.errors["ecstat1"]) expect(record.errors["ecstat1"])

Loading…
Cancel
Save