From ef46c6c2275f585c4cb518cc5f05b57067ac892a Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 14 Nov 2022 14:55:43 +0000 Subject: [PATCH] Change enabled? subsection method to check depends on using log questions and methods instead of a subsection status --- app/models/form/subsection.rb | 6 +----- app/models/lettings_log.rb | 4 ++++ app/models/log.rb | 4 ++++ config/forms/2021_2022.json | 12 ++++++------ config/forms/2022_2023.json | 20 ++++++++++---------- spec/fixtures/forms/2021_2022.json | 7 ++++--- spec/fixtures/forms/2022_2023.json | 2 +- 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index d3ab0ddd2..07e7fe65c 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -20,11 +20,7 @@ class Form::Subsection def enabled?(log) return true unless depends_on - depends_on.any? do |conditions_set| - conditions_set.all? do |subsection_id, dependent_status| - form.get_subsection(subsection_id).status(log) == dependent_status.to_sym - end - end + form.depends_on_met(depends_on, log) end def status(log) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index f09fd1ebd..bc011fdfd 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -507,6 +507,10 @@ class LettingsLog < Log form.get_question("rent_type", self)&.label_from_value(rent_type) end + def non_location_setup_questions_completed? + [needstype, renewal, rent_type, startdate, owning_organisation_id, created_by_id].all?(&:present?) + end + private PIO = PostcodeService.new diff --git a/app/models/log.rb b/app/models/log.rb index 54770515f..abde757e5 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -40,6 +40,10 @@ class Log < ApplicationRecord ethnic_group == 17 end + def managing_organisation_provider_type + managing_organisation&.provider_type + end + private def update_status! diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index a180bcc67..19d8c291d 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -10,7 +10,7 @@ "label": "Property information", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -952,7 +952,7 @@ "label": "Tenancy information", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -1133,7 +1133,7 @@ "label": "Household characteristics", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -5671,7 +5671,7 @@ "label": "Household needs", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -6060,7 +6060,7 @@ "label": "Household situation", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -7302,7 +7302,7 @@ "label": "Income, benefits and outgoings", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index 76595bdc5..2c6d0763f 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -10,7 +10,7 @@ "label": "Property information", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -952,7 +952,7 @@ "label": "Tenancy information", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -1168,7 +1168,7 @@ "label": "Household characteristics", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -5670,7 +5670,7 @@ "label": "Household needs", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -6062,7 +6062,7 @@ "label": "Household situation", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { @@ -7070,7 +7070,7 @@ }, "depends_on": [ { - "managing_organisation.provider_type": "LA", + "managing_organisation_provider_type": "LA", "needstype": 1, "renewal": 0 } @@ -7127,7 +7127,7 @@ }, "depends_on": [ { - "managing_organisation.provider_type": "PRP", + "managing_organisation_provider_type": "PRP", "needstype": 1, "renewal": 0 } @@ -7184,7 +7184,7 @@ }, "depends_on": [ { - "managing_organisation.provider_type": "LA", + "managing_organisation_provider_type": "LA", "needstype": 2, "renewal": 0 } @@ -7244,7 +7244,7 @@ }, "depends_on": [ { - "managing_organisation.provider_type": "PRP", + "managing_organisation_provider_type": "PRP", "needstype": 2, "renewal": 0 } @@ -7261,7 +7261,7 @@ "label": "Income, benefits and outgoings", "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ], "pages": { diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index ac02a62a2..8e73f645b 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -1099,9 +1099,10 @@ "label": "Declaration", "depends_on": [ { - "household_characteristics": "completed", - "household_needs": "completed", - "property_information": "completed" + "armedforces": 1 + }, + { + "armedforces": 3 } ], "pages": { diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index a704a9229..5f5671b6f 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -47,7 +47,7 @@ }, "depends_on": [ { - "setup": "completed" + "non_location_setup_questions_completed?": true } ] }