From 7c8f62a164491390d10ec0edd3f8e8368ff16090 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:31:59 +0100 Subject: [PATCH 1/2] Clear all previous location fields (#2658) --- app/controllers/form_controller.rb | 1 + spec/requests/check_errors_controller_spec.rb | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 8a95464a7..70b6f892b 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -409,6 +409,7 @@ private next if question.subsection.id == "setup" question.page.questions.map(&:id).each { |id| @log[id] = nil } + @log.previous_la_known = nil if question.id == "ppostcode_full" end @log.save! @questions = params[@log.model_name.param_key].keys.reject { |id| %w[clear_question_ids page].include?(id) }.map { |id| @log.form.get_question(id, @log) } diff --git a/spec/requests/check_errors_controller_spec.rb b/spec/requests/check_errors_controller_spec.rb index c101e7959..29130f547 100644 --- a/spec/requests/check_errors_controller_spec.rb +++ b/spec/requests/check_errors_controller_spec.rb @@ -300,6 +300,33 @@ RSpec.describe CheckErrorsController, type: :request do end end + context "and clearing ppostcode_full when previous_la_known is yes" do + let(:params) do + { + id: lettings_log.id, + lettings_log: { + layear: "1", + clear_question_ids: "ppostcode_full", + page: "time_lived_in_local_authority", + }, + check_errors: "", + } + end + + before do + lettings_log.update!(previous_la_known: 1, ppcodenk: 0, ppostcode_full: "AA11AA") + sign_in user + post "/lettings-logs/#{lettings_log.id}/time-lived-in-local-authority", params: + end + + it "clears related previous location fields" do + expect(lettings_log.reload.prevloc).to eq(nil) + expect(lettings_log.reload.previous_la_known).to eq(nil) + expect(lettings_log.reload.ppostcode_full).to eq(nil) + expect(lettings_log.reload.ppcodenk).to eq(nil) + end + end + context "and clearing specific sales question" do let(:params) do { From 54d15d95ef8a45c748e66c01205f542711fb5ec0 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:57:19 +0100 Subject: [PATCH 2/2] CLDC-3420 Check tshortfall for care homes (#2659) * Check tshortfall for care homes * Fix BU tests --- app/models/validations/financial_validations.rb | 5 +++++ config/locales/en.yml | 2 ++ .../validations/financial_validations_spec.rb | 16 ++++++++++++++++ .../lettings/year2023/row_parser_spec.rb | 2 +- .../lettings/year2024/row_parser_spec.rb | 2 +- 5 files changed, 25 insertions(+), 2 deletions(-) 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 e3ef39517..83fe1f292 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -384,6 +384,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." @@ -456,6 +457,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 4e1aa400f..f35cdd097 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 diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 18c28189a..08109f4b9 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -215,7 +215,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do field_131: "101.11", field_132: "1500.19", field_133: "1", - field_134: "234.56", + field_134: "34.56", field_27: "15", field_28: "0", diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index 3910e1281..a8a6bf0da 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -235,7 +235,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do field_127: "13.14", field_128: "101.11", field_129: "1", - field_130: "234.56", + field_130: "34.56", field_24: "15", field_30: now.day.to_s,