From 404d32a77eb8b1c9769272371385fd69bfb0cca9 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 24 Sep 2024 15:02:45 +0100 Subject: [PATCH] Check tshortfall for care homes --- app/models/validations/financial_validations.rb | 5 +++++ config/locales/en.yml | 2 ++ .../validations/financial_validations_spec.rb | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 53e50a92f..724fa9b6e 100644 --- a/app/models/validations/financial_validations.rb +++ b/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") diff --git a/config/locales/en.yml b/config/locales/en.yml index c666746da..86daf8f4c 100644 --- a/config/locales/en.yml +++ b/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" diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index a6eefa708..b1678f3af 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/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