diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index cc8c7d58b..55db7bfe4 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -814,6 +814,10 @@ private housingneeds_other == 1 end + def no_or_unknown_other_housing_needs? + housingneeds_other&.zero? || housing_needs_other == 2 + end + def has_housingneeds? housingneeds == 1 end @@ -826,6 +830,10 @@ private housingneeds == 3 end + def housingneeds_type_not_listed? + housingneeds_type == 3 + end + def should_process_uprn_change? uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023 end diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index a213f6844..cd15d09cf 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -129,7 +129,7 @@ module Validations::HouseholdValidations end 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_type, I18n.t("validations.household.housingneeds.invalid") record.errors.add :housingneeds_other, I18n.t("validations.household.housingneeds.invalid")