From 959cbc070f33547df7bfe441124de09efd3168af Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 20 Dec 2022 10:45:24 +0000 Subject: [PATCH] Mark subsection as completed if it is not displayed in the tasklist and hide it from the UI --- app/models/form/subsection.rb | 8 +++++--- app/models/log.rb | 2 +- app/views/logs/_tasklist.html.erb | 2 +- spec/models/lettings_log_spec.rb | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 07e7fe65c..0266fc448 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -24,9 +24,7 @@ class Form::Subsection end def status(log) - unless enabled?(log) - return :cannot_start_yet - end + return :cannot_start_yet unless enabled?(log) qs = applicable_questions(log) qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) } @@ -49,4 +47,8 @@ class Form::Subsection (q.displayed_to_user?(log) && !q.derived?) || q.has_inferred_check_answers_value?(log) end end + + def displayed_in_tasklist?(_log) + true + end end diff --git a/app/models/log.rb b/app/models/log.rb index c09cdd46a..e9dc9c69a 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -63,7 +63,7 @@ private end def all_fields_completed? - subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq + subsection_statuses = form.subsections.map { |subsection| subsection.status(self) if subsection.displayed_in_tasklist?(self) }.uniq.compact subsection_statuses == [:completed] end diff --git a/app/views/logs/_tasklist.html.erb b/app/views/logs/_tasklist.html.erb index 6c82eb377..df8a3afad 100644 --- a/app/views/logs/_tasklist.html.erb +++ b/app/views/logs/_tasklist.html.erb @@ -9,7 +9,7 @@ <% end %>