diff --git a/app/forms/assessor_interface/assessment_section_form.rb b/app/forms/assessor_interface/assessment_section_form.rb index fa478b15f4..6d12a36c36 100644 --- a/app/forms/assessor_interface/assessment_section_form.rb +++ b/app/forms/assessor_interface/assessment_section_form.rb @@ -78,6 +78,11 @@ def self.name klass.preliminary = assessment_section.preliminary? assessment_section.failure_reasons.each do |failure_reason| + selected_failure_reason = + assessment_section.selected_failure_reasons.find_by( + key: failure_reason, + ) + klass.attribute "#{failure_reason}_checked", :boolean if assessment_section.preliminary? @@ -90,6 +95,9 @@ def self.name klass.validates "#{failure_reason}_work_history_checked", presence: true, if: :"#{failure_reason}_checked" + elsif selected_failure_reason.present? && + selected_failure_reason.work_histories.present? + klass.attribute "#{failure_reason}_work_history_checked" end klass.attribute "#{failure_reason}_notes", :string @@ -122,7 +130,8 @@ def initial_attributes(assessment_section) selected_failure_reasons_hash.each do |key, notes| attributes["#{key}_checked"] = true attributes["#{key}_notes"] = notes[:assessor_feedback] - if FailureReasons.chooses_work_history?(key) + if FailureReasons.chooses_work_history?(key) || + notes[:work_history_ids].present? attributes["#{key}_work_history_checked"] = notes[:work_history_ids] end end diff --git a/app/lib/failure_reasons.rb b/app/lib/failure_reasons.rb index 3ceb200380..b5ef827dfe 100644 --- a/app/lib/failure_reasons.rb +++ b/app/lib/failure_reasons.rb @@ -77,7 +77,7 @@ class FailureReasons WRITTEN_STATEMENT_RECENT = "written_statement_recent", ].freeze - WORK_HISTORY_FAILURE_REASONS = [SCHOOL_DETAILS_CANNOT_BE_VERIFIED].freeze + WORK_HISTORY_REFERENCE_FAILURE_REASONS = [UNRECOGNISED_REFERENCES].freeze ALL = (DECLINABLE + FURTHER_INFORMATIONABLE).freeze @@ -138,6 +138,6 @@ def self.further_information_request_document_type(failure_reason) end def self.chooses_work_history?(failure_reason) - WORK_HISTORY_FAILURE_REASONS.include?(failure_reason.to_s) + WORK_HISTORY_REFERENCE_FAILURE_REASONS.include?(failure_reason.to_s) end end diff --git a/app/view_objects/assessor_interface/assessment_section_view_object.rb b/app/view_objects/assessor_interface/assessment_section_view_object.rb index 7e96d590ed..604d8d5d1f 100644 --- a/app/view_objects/assessor_interface/assessment_section_view_object.rb +++ b/app/view_objects/assessor_interface/assessment_section_view_object.rb @@ -28,7 +28,11 @@ def assessment_section delegate :registration_number, :requires_preliminary_check, to: :application_form - delegate :checks, :failure_reasons, :preliminary?, to: :assessment_section + delegate :checks, + :failure_reasons, + :preliminary?, + :selected_failure_reasons, + to: :assessment_section delegate :region, :country, to: :application_form def notes_label_key_for(failure_reason:) @@ -43,6 +47,10 @@ def notes_placeholder_key_for(failure_reason:) build_key(failure_reason, "placeholder") end + def selected_work_histories_for(failure_reason:) + selected_failure_reasons.find_by(key: failure_reason)&.work_histories + end + def show_form? return true if preliminary? diff --git a/app/views/assessor_interface/assessment_sections/_form.html.erb b/app/views/assessor_interface/assessment_sections/_form.html.erb index e9308e4053..3e1cc781f0 100644 --- a/app/views/assessor_interface/assessment_sections/_form.html.erb +++ b/app/views/assessor_interface/assessment_sections/_form.html.erb @@ -82,7 +82,7 @@ hint: { text: t(view_object.notes_hint_key_for(failure_reason:)) }, placeholder: t(view_object.notes_placeholder_key_for(failure_reason:)), disabled: view_object.disable_form? %> - <% if FailureReasons::chooses_work_history?(failure_reason) %> + <% if FailureReasons.chooses_work_history?(failure_reason) || view_object.selected_work_histories_for(failure_reason:).present? %> <%= f.govuk_check_boxes_fieldset :"#{failure_reason}_work_history_checked", legend: { size: "s" } do %> <% view_object.work_histories.each do |work_history| %> <%= f.govuk_check_box :"#{failure_reason}_work_history_checked", work_history.id, label: { text: work_history.school_name }, disabled: view_object.disable_form? %> diff --git a/app/views/assessor_interface/further_information_requests/new.html.erb b/app/views/assessor_interface/further_information_requests/new.html.erb index 23c9f61420..9c3539bbe1 100644 --- a/app/views/assessor_interface/further_information_requests/new.html.erb +++ b/app/views/assessor_interface/further_information_requests/new.html.erb @@ -4,7 +4,7 @@