Browse Source

Merge pull request #162 from communitiesuk/CLDC-492/validate_hbrentshortfall

CLDC-492: After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?
pull/169/head
Matthew J. Phelan 3 years ago committed by GitHub
parent
commit
2d097d44cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/models/validations/financial_validations.rb

18
app/models/validations/financial_validations.rb

@ -34,4 +34,22 @@ module Validations::FinancialValidations
record.errors.add :earnings, "Net income cannot be less than #{record.applicable_income_range.hard_min} given the tenant's working situation"
end
end
def validate_hbrentshortfall(record)
is_present = record.hbrentshortfall.present?
is_yes = record.hbrentshortfall == "Yes"
hb_donotknow = record.hb == "Do not know"
hb_no_hb_or_uc = record.hb == "Not Housing Benefit or Universal Credit"
hb_uc_no_hb = record.hb == "Universal Credit without housing element and no Housing Benefit"
hb_no_uc = record.hb == "Housing Benefit, but not Universal Credit"
hb_uc_no_he_hb = record.hb == "Universal Credit with housing element, but not Housing Benefit"
hb_and_uc = record.hb == "Universal Credit and Housing Benefit"
conditions = [
{ condition: is_yes && (hb_donotknow || hb_no_hb_or_uc || hb_uc_no_hb), error: "Outstanding amount for basic rent and/or benefit eligible charges can not be 'Yes' if tenant is not in receipt of housing benefit or universal benefit or if benefit is unknown" },
{ condition: (hb_no_uc || hb_uc_no_he_hb || hb_and_uc) && !is_present, error: "Must be completed if Universal credit and/or Housing Benefit received" },
]
conditions.each { |condition| condition[:condition] ? (record.errors.add :hbrentshortfall, condition[:error]) : nil }
end
end

Loading…
Cancel
Save