diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 9f35df7ba..de3311b45 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -25,7 +25,6 @@ class CaseLog < ApplicationRecord before_validation :reset_scheme_location!, if: :scheme_changed?, unless: :location_changed? before_validation :process_postcode_changes!, if: :postcode_full_changed? before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed? - before_validation :set_housingneeds_fields, if: :housingneeds? before_validation :reset_invalidated_dependent_fields! before_validation :reset_location_fields!, unless: :postcode_known? before_validation :reset_previous_location_fields!, unless: :previous_postcode_known? @@ -759,25 +758,4 @@ private def unknown_housingneeds? housingneeds == 3 end - - def set_housingneeds_fields - set_housingneeds_values_to_zero - - self.housingneeds_a = 1 if fully_wheelchair_accessible? - self.housingneeds_b = 1 if essential_wheelchair_access? - self.housingneeds_c = 1 if level_access_housing? - self.housingneeds_f = 1 if other_housingneeds? - set_housingneeds_values_to_zero unless has_housingneeds? - self.housingneeds_g = 1 if no_housingneeds? - self.housingneeds_h = 1 if unknown_housingneeds? - end - - def set_housingneeds_values_to_zero - self.housingneeds_a = 0 - self.housingneeds_b = 0 - self.housingneeds_c = 0 - self.housingneeds_f = 0 - self.housingneeds_g = 0 - self.housingneeds_h = 0 - end end diff --git a/app/models/derived_variables/case_log_variables.rb b/app/models/derived_variables/case_log_variables.rb index 9c6090918..29fe4adb3 100644 --- a/app/models/derived_variables/case_log_variables.rb +++ b/app/models/derived_variables/case_log_variables.rb @@ -69,6 +69,8 @@ module DerivedVariables::CaseLogVariables self.voiddate = startdate end end + + set_housingneeds_fields if housingneeds? end private @@ -185,4 +187,25 @@ private self.location = scheme.locations.first end end + + def set_housingneeds_fields + set_housingneeds_values_to_zero + + self.housingneeds_a = 1 if fully_wheelchair_accessible? + self.housingneeds_b = 1 if essential_wheelchair_access? + self.housingneeds_c = 1 if level_access_housing? + self.housingneeds_f = 1 if other_housingneeds? + set_housingneeds_values_to_zero unless has_housingneeds? + self.housingneeds_g = 1 if no_housingneeds? + self.housingneeds_h = 1 if unknown_housingneeds? + end + + def set_housingneeds_values_to_zero + self.housingneeds_a = 0 + self.housingneeds_b = 0 + self.housingneeds_c = 0 + self.housingneeds_f = 0 + self.housingneeds_g = 0 + self.housingneeds_h = 0 + end end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 826b0838f..f498cfbe4 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -59,6 +59,7 @@ "housingneeds": 1, "housingneeds_type": 2, "housingneeds_other": 0, + "housingneeds_c": 1, "illness_type_1":null, "illness_type_2":null, "illness_type_3":null,