Browse Source

Code review

pull/650/head
Stéphane Meny 3 years ago
parent
commit
3a77bca91a
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 30
      app/models/validations/financial_validations.rb

30
app/models/validations/financial_validations.rb

@ -51,25 +51,25 @@ module Validations::FinancialValidations
end
def validate_tshortfall(record)
return unless record.startdate
cannot_have_outstanding_amount = if record.collection_start_year <= 2021
record.has_hbrentshortfall? &&
(record.benefits_unknown? ||
record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?)
else
record.has_hbrentshortfall? &&
(record.benefits_unknown? ||
record.receives_no_benefits? ||
record.tenant_refuses_to_say_benefits?)
end
if cannot_have_outstanding_amount
if record.has_hbrentshortfall? && no_known_benefits?(record)
record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end
end
def no_known_benefits?(record)
return true unless record.collection_start_year
if record.collection_start_year <= 2021
record.benefits_unknown? ||
record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?
else
record.benefits_unknown? ||
record.receives_no_benefits? ||
record.tenant_refuses_to_say_benefits?
end
end
def validate_rent_amount(record)
if record.brent.present? && record.tshortfall.present? && record.brent < record.tshortfall * 2
record.errors.add :brent, I18n.t("validations.financial.rent.less_than_double_shortfall", tshortfall: record.tshortfall * 2)

Loading…
Cancel
Save