From cb8b86f39e4caa367ab508acfab03131f30c12d0 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 18 Apr 2024 10:59:57 +0100 Subject: [PATCH 1/2] CLDC-3408: Adjust outstanding amount validation to compare to total charges (#2385) --- .../validations/financial_validations.rb | 6 ++--- config/locales/en.yml | 4 ++-- .../validations/financial_validations_spec.rb | 22 +++++++++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 0b9209281..e0e3f081e 100644 --- a/app/models/validations/financial_validations.rb +++ b/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 diff --git a/config/locales/en.yml b/config/locales/en.yml index ef8674c44..8262ffe67 100644 --- a/config/locales/en.yml +++ b/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: diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index c68a3b7b2..56ae38c65 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/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 From d1ad0021a92a57185fb60f2e34a12ce8c0e41fec Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 18 Apr 2024 11:00:20 +0100 Subject: [PATCH 2/2] CLDC-2470: Order bulk upload error rows numerically (#2381) --- app/models/bulk_upload_error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bulk_upload_error.rb b/app/models/bulk_upload_error.rb index b9ad3ddde..c9ca14b0f 100644 --- a/app/models/bulk_upload_error.rb +++ b/app/models/bulk_upload_error.rb @@ -1,7 +1,7 @@ class BulkUploadError < ApplicationRecord belongs_to :bulk_upload - scope :order_by_row, -> { order(row: :asc) } + scope :order_by_row, -> { order("row::integer ASC") } scope :order_by_cell, -> { order(Arel.sql("LPAD(cell, 10, '0')")) } scope :order_by_col, -> { order(Arel.sql("LPAD(col, 10, '0')")) } end