Skip to content

Commit

Permalink
Update statuses
Browse files Browse the repository at this point in the history
This adds the ability for the status updater class to also update the
statuses value, ensuring that it's kept up to date with the status.
  • Loading branch information
thomasleese committed Sep 28, 2023
1 parent cba31d5 commit cc6757c
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 42 deletions.
6 changes: 6 additions & 0 deletions app/components/status_tag/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def classes
accepted: "green",
assessment: "blue",
assessment_in_progress: "blue",
assessment_not_started: "grey",
awarded: "green",
awarded_pending_checks: "turquoise",
cannot_start: "grey",
Expand All @@ -34,6 +35,7 @@ def classes
not_started: "grey",
overdue: "pink",
overdue_further_information: "pink",
overdue_lops: "pink",
overdue_professional_standing: "pink",
overdue_qualification: "pink",
overdue_reference: "pink",
Expand All @@ -42,6 +44,7 @@ def classes
preliminary_check: "pink",
received: "purple",
received_further_information: "purple",
received_lops: "purple",
received_professional_standing: "purple",
received_qualification: "purple",
received_reference: "purple",
Expand All @@ -51,8 +54,11 @@ def classes
submitted: "grey",
valid: "green",
verification: "yellow",
verification_in_progress: "blue",
verification_not_started: "grey",
waiting_on: "yellow",
waiting_on_further_information: "yellow",
waiting_on_lops: "yellow",
waiting_on_professional_standing: "yellow",
waiting_on_qualification: "yellow",
waiting_on_reference: "yellow",
Expand Down
110 changes: 73 additions & 37 deletions app/lib/application_form_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def call
ActiveRecord::Base.transaction do
application_form.update!(
overdue_further_information:,
overdue_professional_standing:,
overdue_professional_standing: overdue_lops,
overdue_qualification:,
overdue_reference:,
received_further_information:,
received_professional_standing:,
received_professional_standing: received_lops,
received_qualification:,
received_reference:,
waiting_on_further_information:,
waiting_on_professional_standing:,
waiting_on_professional_standing: waiting_on_lops,
waiting_on_qualification:,
waiting_on_reference:,
)
Expand Down Expand Up @@ -52,6 +52,10 @@ def call
new_value: stage,
)
end

if statuses != application_form.statuses
application_form.update!(statuses:)
end
end
end

Expand All @@ -63,7 +67,7 @@ def overdue_further_information
overdue?(requestables: further_information_requests)
end

def overdue_professional_standing
def overdue_lops
return false if teaching_authority_provides_written_statement
overdue?(requestables: professional_standing_requests)
end
Expand All @@ -81,7 +85,7 @@ def received_further_information
received?(requestables: further_information_requests)
end

def received_professional_standing
def received_lops
return false if teaching_authority_provides_written_statement

professional_standing_requests
Expand Down Expand Up @@ -125,7 +129,7 @@ def waiting_on_further_information
waiting_on?(requestables: further_information_requests)
end

def waiting_on_professional_standing
def waiting_on_lops
waiting_on?(requestables: professional_standing_requests)
end

Expand All @@ -152,15 +156,14 @@ def status
"awarded_pending_checks"
elsif preliminary_check?
"preliminary_check"
elsif overdue_further_information || overdue_professional_standing ||
elsif overdue_further_information || overdue_lops ||
overdue_qualification || overdue_reference
"overdue"
elsif received_further_information || received_professional_standing ||
elsif received_further_information || received_lops ||
received_qualification || received_reference
"received"
elsif waiting_on_further_information ||
waiting_on_professional_standing || waiting_on_qualification ||
waiting_on_reference
elsif waiting_on_further_information || waiting_on_lops ||
waiting_on_qualification || waiting_on_reference
"waiting_on"
elsif assessment&.any_not_preliminary_section_finished?
"assessment_in_progress"
Expand All @@ -173,19 +176,22 @@ def status

def action_required_by
@action_required_by ||=
if status == "preliminary_check"
if application_form.withdrawn_at.present? ||
application_form.declined_at.present? ||
application_form.awarded_at.present?
"none"
elsif preliminary_check?
"admin"
elsif %w[
potential_duplicate_in_dqt
awarded_pending_checks
overdue
received
assessment_in_progress
submitted
].include?(status)
elsif dqt_trn_request.present? || overdue_further_information ||
overdue_lops || overdue_qualification || overdue_reference ||
received_further_information || received_lops ||
received_qualification || received_reference
"assessor"
elsif status == "waiting_on"
elsif waiting_on_further_information || waiting_on_lops ||
waiting_on_qualification || waiting_on_reference
"external"
elsif application_form.submitted_at.present?
"assessor"
else
"none"
end
Expand All @@ -200,19 +206,11 @@ def stage
elsif dqt_trn_request.present?
"review"
elsif preliminary_check? ||
(
teaching_authority_provides_written_statement &&
waiting_on_professional_standing
)
(teaching_authority_provides_written_statement && waiting_on_lops)
"pre_assessment"
elsif overdue_professional_standing || overdue_qualification ||
overdue_reference ||
(
!teaching_authority_provides_written_statement &&
received_professional_standing
) || received_qualification || received_reference ||
waiting_on_professional_standing || waiting_on_qualification ||
waiting_on_reference
elsif overdue_lops || overdue_qualification || overdue_reference ||
received_lops || received_qualification || received_reference ||
waiting_on_lops || waiting_on_qualification || waiting_on_reference
"verification"
elsif overdue_further_information || received_further_information ||
waiting_on_further_information ||
Expand All @@ -225,6 +223,35 @@ def stage
end
end

def statuses
@statuses ||=
if application_form.withdrawn_at.present?
%w[withdrawn]
elsif application_form.declined_at.present?
%w[declined]
elsif application_form.awarded_at.present?
%w[awarded]
elsif dqt_trn_request.present?
if dqt_trn_request.potential_duplicate?
%w[potential_duplicate_in_dqt]
else
%w[awarded_pending_checks]
end
elsif assessment.present?
if preliminary_check?
%w[preliminary_check] + requestable_statuses
elsif requestable_statuses.present?
requestable_statuses
elsif assessment.any_not_preliminary_section_finished?
%w[assessment_in_progress]
else
%w[assessment_not_started]
end
else
%w[draft]
end
end

delegate :assessment,
:dqt_trn_request,
:region,
Expand All @@ -234,14 +261,23 @@ def stage
delegate :references_verified, to: :assessment, allow_nil: true

def preliminary_check?
application_form.submitted_at.present? &&
application_form.requires_preliminary_check &&
return false if assessment.nil?

application_form.requires_preliminary_check &&
(
assessment&.any_preliminary_section_failed? ||
!assessment&.all_preliminary_sections_passed?
assessment.any_preliminary_section_failed? ||
!assessment.all_preliminary_sections_passed?
)
end

def requestable_statuses
@requestable_statuses ||=
%w[overdue received waiting_on]
.product(%w[further_information lops qualification reference])
.map { |status, requestable| "#{status}_#{requestable}" }
.filter { |column| send(column) }
end

def further_information_requests
@further_information_requests ||=
assessment&.further_information_requests&.to_a || []
Expand Down
6 changes: 6 additions & 0 deletions config/locales/components.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ en:
accepted: Accepted
assessment: Assessment
assessment_in_progress: Assessment in progress
assessment_not_started: Assessment not started
awarded: Awarded
awarded_pending_checks: Award pending
cannot_start: Cannot start
Expand All @@ -16,6 +17,7 @@ en:
not_started: Not started
overdue: Overdue
overdue_further_information: Overdue further information
overdue_lops: Overdue LOPS
overdue_professional_standing: Overdue professional standing
overdue_qualification: Overdue qualification
overdue_reference: Overdue reference
Expand All @@ -24,6 +26,7 @@ en:
preliminary_check: Preliminary check
received: Received
received_further_information: Received further information
received_lops: Received LOPS
received_professional_standing: Received professional standing
received_qualification: Received qualification
received_reference: Received reference
Expand All @@ -33,8 +36,11 @@ en:
submitted: Not started
valid: Valid
verification: Verification
verification_in_progress: Verification in progress
verification_not_started: Verification not started
waiting_on: Waiting on
waiting_on_further_information: Waiting on further information
waiting_on_lops: Waiting on LOPS
waiting_on_professional_standing: Waiting on professional standing
waiting_on_qualification: Waiting on qualification
waiting_on_reference: Waiting on reference
Expand Down
Loading

0 comments on commit cc6757c

Please sign in to comment.