diff --git a/app/models/form.rb b/app/models/form.rb
index df4d3c659..4a2687752 100644
--- a/app/models/form.rb
+++ b/app/models/form.rb
@@ -50,7 +50,7 @@ class Form
def next_incomplete_section_redirect_path(subsection, case_log)
subsection_ids = subsections.map(&:id)
- if case_log.status == "completed"
+ if case_log.status == "completed" || all_subsections_except_declaration_completed?(case_log)
next_subsection = get_subsection(subsection_ids[subsection_ids.length - 1])
first_question_in_subsection = next_subsection.pages.first.id
return first_question_in_subsection.to_s.dasherize
@@ -62,6 +62,7 @@ class Form
if next_subsection.id == "declaration" && case_log.status != "completed"
next_subsection = get_subsection(subsection_ids[0])
end
+
if next_subsection.status(case_log) == :completed
next_incomplete_section_redirect_path(next_subsection, case_log)
else
@@ -70,6 +71,14 @@ class Form
end
end
+ def all_subsections_except_declaration_completed?(case_log)
+ subsection_ids = subsections.map(&:id)
+ subsection_ids.delete_at(subsection_ids.length - 1)
+ return true if subsection_ids.all? { |subsection_id| get_subsection(subsection_id).status(case_log) == :completed }
+
+ false
+ end
+
def conditional_question_conditions
conditions = questions.map { |q| Hash(q.id => q.conditional_for) if q.conditional_for.present? }.compact
conditions.map { |c|
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb
index c9bf0b713..c9d3e0d5d 100644
--- a/app/views/form/check_answers.html.erb
+++ b/app/views/form/check_answers.html.erb
@@ -23,9 +23,9 @@
<%= form_with model: @case_log, method: "get" do |f| %>
<%= f.govuk_submit 'Save and continue' do %>
- <% if @case_log.status == "in_progress" %>
+ <% if @case_log.status == "in_progress" && @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) == false %>
>Save and go to next incomplete section
- <% elsif @case_log.status == "completed" %>
+ <% elsif @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) %>
>Save and go to submit
<% end%>
<% end %>