Skip to content

Commit

Permalink
Merge pull request #3531 from DFE-Digital/CAPT-1797/qualification-rep…
Browse files Browse the repository at this point in the history
…ort-tweak

CAPT 1797/qualification report tweak
  • Loading branch information
rjlynch authored Jan 29, 2025
2 parents d0b2f12 + b0ee6aa commit 4e2bbd6
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 70 deletions.
50 changes: 19 additions & 31 deletions app/models/reports/failed_qualification_claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def initialize
@claims = Claim
.approved
.where(academic_year: AcademicYear.current)
.joins(:tasks).merge(Task.where(name: "qualifications", passed: false))
.includes(:eligibility, decisions: :created_by)
.joins(:tasks).merge(
Task.qualifications.where(passed: false).or(
Task.qualifications.claim_verifier_match_none
)
)
.includes(:eligibility, :notes, decisions: :created_by)
end

def to_csv
Expand Down Expand Up @@ -54,10 +58,10 @@ def to_a
qualification,
itt_academic_year,
eligible_itt_subject,
itt_subjects,
itt_start_date,
qts_award_date,
qualification_name
parse_note("ITT subjects"),
parse_note("ITT start date"),
parse_note("QTS award date"),
parse_note("Qualification name")
]
end

Expand All @@ -84,34 +88,18 @@ def qualification
claim.eligibility.try(:qualification)
end

def itt_subjects
dqt_teacher_record&.itt_subjects&.join(", ")
end

def itt_start_date
date = dqt_teacher_record&.itt_start_date

return unless date

I18n.l(date, format: :day_month_year)
end
# dqt information isn't stored on any claims on production.
# We don't want to make an API call for each claim in this report, so
# instead we parse the note to get the information for the report.
def parse_note(label)
return unless dqt_note

def qts_award_date
date = dqt_teacher_record&.qts_award_date

return unless date

I18n.l(date, format: :day_month_year)
match = dqt_note.body.match(/#{label}: (.*)/)
match ? match[1].strip : nil
end

def qualification_name
dqt_teacher_record&.qualification_name
end

def dqt_teacher_record
@dqt_teacher_record ||= if claim.has_dqt_record?
Dqt::Teacher.new(claim.dqt_teacher_status)
end
def dqt_note
@dqt_note ||= claim.notes.find_by(label: "qualifications")
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Task < ApplicationRecord
payroll_gender
].freeze

NAMES.each { |name| scope name.to_sym, -> { where(name: name) } }

belongs_to :claim
belongs_to :created_by, class_name: "DfeSignIn::User", optional: true

Expand All @@ -44,7 +46,6 @@ class Task < ApplicationRecord
scope :automated, -> { where(manual: false) }
scope :passed_automatically, -> { automated.where(passed: true) }

scope :census_subjects_taught, -> { where(name: "census_subjects_taught") }
scope :no_data_census_subjects_taught, -> { census_subjects_taught.where(passed: nil, claim_verifier_match: nil) }

def to_param
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
trait :automated do
manual { false }
end

trait :claim_verifier_context do
to_create { it.save!(context: :claim_verifier) }
end
end
end
Loading

0 comments on commit 4e2bbd6

Please sign in to comment.