From 055b493b441eb7b5e67f5d019b7fcb52f9ebcc29 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 26 Feb 2025 16:10:40 +0000 Subject: [PATCH] Clear derived working situation of child under 16 when age is changed to 16 or above --- app/models/derived_variables/lettings_log_variables.rb | 9 +++++++++ app/models/derived_variables/sales_log_variables.rb | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index f584b6238..1e2aab790 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -72,6 +72,7 @@ module DerivedVariables::LettingsLogVariables self.beds = 1 end + clear_child_ecstat_for_age_changes! child_under_16_constraints! self.hhtype = household_type @@ -243,6 +244,14 @@ private end end + def clear_child_ecstat_for_age_changes! + (2..8).each do |idx| + if public_send("age#{idx}_changed?") && self["ecstat#{idx}"] == 9 + self["ecstat#{idx}"] = nil + end + end + end + def household_type return unless totelder && totadult && totchild diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb index ef4997283..ff8cd4916 100644 --- a/app/models/derived_variables/sales_log_variables.rb +++ b/app/models/derived_variables/sales_log_variables.rb @@ -46,6 +46,7 @@ module DerivedVariables::SalesLogVariables if saledate && form.start_year_2024_or_later? self.soctenant = soctenant_from_prevten_values + clear_child_ecstat_for_age_changes! child_under_16_constraints! end @@ -181,6 +182,15 @@ private end end + def clear_child_ecstat_for_age_changes! + start_index = joint_purchase? ? 3 : 2 + (start_index..6).each do |idx| + if public_send("age#{idx}_changed?") && self["ecstat#{idx}"] == 9 + self["ecstat#{idx}"] = nil + end + end + end + def household_type return unless total_elder && total_adult && totchild