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. 27
      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. 24
      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"
@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
@max = 999_999
@step = 1
@width = 5
@prefix = "£"

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

@ -18,7 +18,14 @@ 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
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
def validate_cash_discount(record)
return unless record.cashdis
@ -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 :type, I18n.t("validations.financial.staircasing.older_person_percentage_owned_maximum_75")
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

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

@ -19,6 +19,10 @@ module Validations::Sales::HouseholdValidations
end
end
def validate_relat2(record)
child_income_validation(record, :relat2)
end
private
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
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
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"
freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total"
income1:
income:
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"
rent:
less_than_shortfall: "Enter an amount that is more than the shortfall in basic rent"

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

@ -16,15 +16,17 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.ecstat1 = ecstat
financial_validator.validate_income1(record)
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"])
.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"])
.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["la"])
.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["postcode_full"])
.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))
end
end
@ -52,15 +54,17 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.ecstat1 = ecstat
financial_validator.validate_income1(record)
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.income.over_hard_max", hard_max: 90_000))
expect(record.errors["income1"])
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000))
expect(record.errors["ecstat1"])
.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["ownershipsch"])
.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["la"])
.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["postcode_full"])
.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))
end
end

Loading…
Cancel
Save