Browse Source

feat: update validation

pull/2183/head
natdeanlewissoftwire 2 years ago committed by Kat
parent
commit
6f95aeb6f4
  1. 8
      app/models/lettings_log.rb
  2. 2
      app/models/validations/household_validations.rb

8
app/models/lettings_log.rb

@ -814,6 +814,10 @@ private
housingneeds_other == 1 housingneeds_other == 1
end end
def no_or_unknown_other_housing_needs?
housingneeds_other&.zero? || housing_needs_other == 2
end
def has_housingneeds? def has_housingneeds?
housingneeds == 1 housingneeds == 1
end end
@ -826,6 +830,10 @@ private
housingneeds == 3 housingneeds == 3
end end
def housingneeds_type_not_listed?
housingneeds_type == 3
end
def should_process_uprn_change? def should_process_uprn_change?
uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023 uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023
end end

2
app/models/validations/household_validations.rb

@ -129,7 +129,7 @@ module Validations::HouseholdValidations
end end
def validate_combination_of_housing_needs_responses(record) def validate_combination_of_housing_needs_responses(record)
if record.housingneeds == 1 && record.housingneeds_type == 3 && record.housingneeds_other&.zero? if record.has_housingneeds? && record.housingneeds_type_not_listed? && record.no_or_unknown_other_housing_needs?
record.errors.add :housingneeds, I18n.t("validations.household.housingneeds.invalid") record.errors.add :housingneeds, I18n.t("validations.household.housingneeds.invalid")
record.errors.add :housingneeds_type, I18n.t("validations.household.housingneeds.invalid") record.errors.add :housingneeds_type, I18n.t("validations.household.housingneeds.invalid")
record.errors.add :housingneeds_other, I18n.t("validations.household.housingneeds.invalid") record.errors.add :housingneeds_other, I18n.t("validations.household.housingneeds.invalid")

Loading…
Cancel
Save