Browse Source

Check tshortfall for care homes

pull/2659/head
Kat 2 years ago
parent
commit
404d32a77e
  1. 5
      app/models/validations/financial_validations.rb
  2. 2
      config/locales/en.yml
  3. 16
      spec/models/validations/financial_validations_spec.rb

5
app/models/validations/financial_validations.rb

@ -121,6 +121,11 @@ module Validations::FinancialValidations
def validate_rent_amount(record)
if record.wtshortfall
if record.is_supported_housing? && record.wchchrg && (record.wtshortfall > record.wchchrg)
record.errors.add :tshortfall, message: I18n.t("validations.financial.tshortfall.more_than_carehome_charge")
record.errors.add :chcharge, I18n.t("validations.financial.carehome.less_than_shortfall")
end
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")

2
config/locales/en.yml

@ -382,6 +382,7 @@ en:
tshortfall:
outstanding_amount_not_expected: "You cannot answer the outstanding amount question if you don’t have outstanding rent or charges"
more_than_total_charge: "Enter a value less than the total charge"
more_than_carehome_charge: "Enter a value less than the care home 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"
@ -454,6 +455,7 @@ en:
carehome:
out_of_range: "Household rent and other charges must be between %{min_chcharge} and %{max_chcharge} if paying %{period}"
not_provided: "Enter how much rent and other charges the household pays %{period}"
less_than_shortfall: "The care home charge must be more than the outstanding amount"
cash_discount_invalid: "Cash discount must be £0 - £999,999"
staircasing:
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage %{buyer_now_owns} must be more than percentage bought in this transaction"

16
spec/models/validations/financial_validations_spec.rb

@ -123,6 +123,22 @@ RSpec.describe Validations::FinancialValidations do
.to include(match I18n.t("validations.financial.tshortfall.more_than_total_charge"))
end
it "validates that carehome charge is no less than the shortfall" do
record.hb = 6
record.hbrentshortfall = 1
record.tshortfall_known = 0
record.tshortfall = 299.50
record.chcharge = 198
record.needstype = 2
record.period = 2
record.set_derived_fields!
financial_validator.validate_rent_amount(record)
expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.less_than_shortfall"))
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.tshortfall.more_than_carehome_charge"))
end
it "expects that rent can be less than the shortfall if total charge is higher" do
record.hb = 6
record.hbrentshortfall = 1

Loading…
Cancel
Save