From a1564a25d3c9d6e29935235969d1e1f55eb4b994 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Thu, 6 Apr 2023 10:58:52 +0100 Subject: [PATCH] refactor some depends on and amend LEttingsLog method to improve readability --- app/models/form/lettings/pages/outstanding_amount.rb | 2 +- app/models/lettings_log.rb | 6 +++++- app/models/validations/financial_validations.rb | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/form/lettings/pages/outstanding_amount.rb b/app/models/form/lettings/pages/outstanding_amount.rb index d624433ea..876307069 100644 --- a/app/models/form/lettings/pages/outstanding_amount.rb +++ b/app/models/form/lettings/pages/outstanding_amount.rb @@ -2,7 +2,7 @@ class Form::Lettings::Pages::OutstandingAmount < ::Form::Page def initialize(id, hsh, subsection) super @id = "outstanding_amount" - @depends_on = [{ "hb" => 1, "hbrentshortfall" => 1 }, { "hb" => 6, "hbrentshortfall" => 1 }] + @depends_on = [{ "receives_any_housing_benefit?" => true, "has_housing_benefit_rent_shortfall?" => true }] end def questions diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 025bdaf6b..2cd3935ec 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -214,7 +214,7 @@ class LettingsLog < Log needstype == 2 end - def has_hbrentshortfall? + def has_housing_benefit_rent_shortfall? # 1: Yes hbrentshortfall == 1 end @@ -379,6 +379,10 @@ class LettingsLog < Log hb == 6 end + def receives_any_housing_benefit? + receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? + end + def receives_no_benefits? # 9: None hb == 9 diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 5fba288bb..bea08f7d7 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -3,7 +3,7 @@ module Validations::FinancialValidations # Validations methods need to be called 'validate_' to run on model save # or 'validate_' to run on submit as well def validate_outstanding_rent_amount(record) - if !record.has_hbrentshortfall? && record.tshortfall.present? + if !record.has_housing_benefit_rent_shortfall? && record.tshortfall.present? record.errors.add :tshortfall, :no_outstanding_charges, message: I18n.t("validations.financial.tshortfall.outstanding_amount_not_required") end end @@ -54,7 +54,7 @@ module Validations::FinancialValidations end def validate_tshortfall(record) - if record.has_hbrentshortfall? && no_known_benefits?(record) + if record.has_housing_benefit_rent_shortfall? && no_known_benefits?(record) record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") end end