Browse Source

CLDC-3408: Adjust outstanding amount validation to compare to total charges (#2385)

CLDC-2831-page-load^2
Rachael Booth 8 months ago committed by GitHub
parent
commit
cb8b86f39e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      app/models/validations/financial_validations.rb
  2. 4
      config/locales/en.yml
  3. 22
      spec/models/validations/financial_validations_spec.rb

6
app/models/validations/financial_validations.rb

@ -121,9 +121,9 @@ module Validations::FinancialValidations
def validate_rent_amount(record)
if record.wtshortfall
if record.wrent && (record.wtshortfall > record.wrent)
record.errors.add :tshortfall, :more_than_rent, message: I18n.t("validations.financial.tshortfall.more_than_rent")
record.errors.add :brent, I18n.t("validations.financial.rent.less_than_shortfall")
if record.wtcharge && (record.wtshortfall > record.wtcharge)
record.errors.add :tshortfall, :more_than_rent, message: I18n.t("validations.financial.tshortfall.more_than_total_charge")
record.errors.add :tcharge, I18n.t("validations.financial.tcharge.less_than_shortfall")
elsif record.wtshortfall < 0.01
record.errors.add :tshortfall, :must_be_positive, message: I18n.t("validations.financial.tshortfall.must_be_positive")
end

4
config/locales/en.yml

@ -361,7 +361,7 @@ en:
financial:
tshortfall:
outstanding_amount_not_expected: "You cannot answer the outstanding amount question if you don’t have outstanding rent or charges"
more_than_rent: "Enter a value less than the basic rent amount"
more_than_total_charge: "Enter a value less than the total charge"
must_be_positive: "Enter a value over £0.01 as you told us there is an outstanding amount"
hbrentshortfall:
outstanding_amount_not_expected: "Answer must be ‘yes’ as you have answered the outstanding amount question"
@ -381,7 +381,6 @@ en:
child_has_income: "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"
out_of_range: "Enter a value for the %{charge_name} between £0 and %{maximum_per_period} paid %{frequency}. %{maximum_per_period} is the max limit for rent and charges paid %{frequency} for %{letting_type} lettings owned by a %{provider_type}."
ecstat:
over_hard_max: "The household’s income of %{earnings} %{frequency} is too high given the household’s working situation"
@ -427,6 +426,7 @@ en:
missing_charges: "Please enter the %{question}. If there is no %{question}, please enter '0'."
tcharge:
under_10: "Enter a total charge that is at least £10.00 per week"
less_than_shortfall: "The total charge must be more than the outstanding amount"
rent_period:
invalid_for_org: "%{org_name} does not charge rent %{rent_period}"
carehome:

22
spec/models/validations/financial_validations_spec.rb

@ -107,19 +107,33 @@ RSpec.describe Validations::FinancialValidations do
.to include(match I18n.t("validations.financial.tshortfall.must_be_positive"))
end
it "validates that basic rent is no less than the shortfall" do
it "validates that total charge is no less than the shortfall" do
record.hb = 6
record.hbrentshortfall = 1
record.tshortfall_known = 0
record.tshortfall = 299.50
record.brent = 198
record.scharge = 50
record.period = 2
record.set_derived_fields!
financial_validator.validate_rent_amount(record)
expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.rent.less_than_shortfall"))
expect(record.errors["tcharge"])
.to include(match I18n.t("validations.financial.tcharge.less_than_shortfall"))
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.tshortfall.more_than_rent"))
.to include(match I18n.t("validations.financial.tshortfall.more_than_total_charge"))
end
it "expects that rent can be less than the shortfall if total charge is higher" do
record.hb = 6
record.hbrentshortfall = 1
record.tshortfall_known = 0
record.tshortfall = 299.50
record.brent = 198
record.scharge = 102
record.period = 2
record.set_derived_fields!
financial_validator.validate_rent_amount(record)
expect(record.errors).to be_empty
end
end
end

Loading…
Cancel
Save