Browse Source

refactor some depends on and amend LEttingsLog method to improve readability

pull/1507/head
Arthur Campbell 3 years ago
parent
commit
a1564a25d3
  1. 2
      app/models/form/lettings/pages/outstanding_amount.rb
  2. 6
      app/models/lettings_log.rb
  3. 4
      app/models/validations/financial_validations.rb

2
app/models/form/lettings/pages/outstanding_amount.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::OutstandingAmount < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "outstanding_amount" @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 end
def questions def questions

6
app/models/lettings_log.rb

@ -214,7 +214,7 @@ class LettingsLog < Log
needstype == 2 needstype == 2
end end
def has_hbrentshortfall? def has_housing_benefit_rent_shortfall?
# 1: Yes # 1: Yes
hbrentshortfall == 1 hbrentshortfall == 1
end end
@ -379,6 +379,10 @@ class LettingsLog < Log
hb == 6 hb == 6
end end
def receives_any_housing_benefit?
receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit?
end
def receives_no_benefits? def receives_no_benefits?
# 9: None # 9: None
hb == 9 hb == 9

4
app/models/validations/financial_validations.rb

@ -3,7 +3,7 @@ module Validations::FinancialValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save # Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record) 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") record.errors.add :tshortfall, :no_outstanding_charges, message: I18n.t("validations.financial.tshortfall.outstanding_amount_not_required")
end end
end end
@ -54,7 +54,7 @@ module Validations::FinancialValidations
end end
def validate_tshortfall(record) 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") record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end end
end end

Loading…
Cancel
Save