Skip to content

Commit

Permalink
Update queries to exclude ParticipantDeclaration::Mentor
Browse files Browse the repository at this point in the history
Update factories to create correct mentor/ect declarations. Update calculators
and reports to only include ECT declarations (as mentor declarations will be on
a separate calculator).
  • Loading branch information
ethax-ross committed Dec 19, 2024
1 parent 4aa4026 commit af684e4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions app/models/participant_profile/ect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ParticipantProfile::ECT < ParticipantProfile::ECF
belongs_to :mentor_profile, class_name: "Mentor", optional: true
has_one :mentor, through: :mentor_profile, source: :user

has_many :participant_declarations, class_name: "ParticipantDeclaration::ECT", foreign_key: :participant_profile_id

scope :awaiting_induction_registration, lambda {
where(induction_start_date: nil).joins(:ecf_participant_eligibility).merge(ECFParticipantEligibility.waiting_for_induction)
}
Expand Down
2 changes: 2 additions & 0 deletions app/models/participant_profile/mentor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ParticipantProfile::Mentor < ParticipantProfile::ECF
has_many :school_mentors, dependent: :destroy, foreign_key: :participant_profile_id
has_many :schools, through: :school_mentors

has_many :participant_declarations, class_name: "ParticipantDeclaration::Mentor", foreign_key: :participant_profile_id

attribute :mentor_completion_reason, :string
enum mentor_completion_reason: {
completed_declaration_received: "completed_declaration_received",
Expand Down
6 changes: 3 additions & 3 deletions app/services/finance/ecf/assurance_report/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(statement)
end

def participant_declarations
ParticipantDeclaration::ECF.find_by_sql(sql)
ParticipantDeclaration::ECT.find_by_sql(sql)
end

private
Expand Down Expand Up @@ -80,13 +80,13 @@ def sql
JOIN schools sc ON sc.id = latest_induction_record.school_id
LEFT OUTER JOIN ecf_participant_eligibilities epe ON epe.participant_profile_id = pp.id
JOIN delivery_partners dp ON dp.id = COALESCE(pd.delivery_partner_id, latest_induction_record.delivery_partner_id)
WHERE pd.type = 'ParticipantDeclaration::ECF' AND #{where_values}
WHERE pd.type = 'ParticipantDeclaration::ECT' AND #{where_values}
ORDER BY u.full_name ASC
EOSQL
end

def where_values
ParticipantDeclaration::ECF.sanitize_sql_for_conditions(["clp.id = ? AND s.id = ?", statement.cpd_lead_provider_id, statement.id])
ParticipantDeclaration::ECT.sanitize_sql_for_conditions(["clp.id = ? AND s.id = ?", statement.cpd_lead_provider_id, statement.id])
end
end
end
Expand Down
16 changes: 9 additions & 7 deletions app/services/finance/ecf/output_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module ECF
class OutputCalculator
attr_reader :statement

DECLARATION_TYPE = "ParticipantDeclaration::ECT"

def initialize(statement:)
@statement = statement
end
Expand Down Expand Up @@ -181,7 +183,7 @@ def previous_fill_level_for_declaration_type(declaration_type)
.where(statement: statement.previous_statements)
.billable
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: })
.where(participant_declarations: { declaration_type:, type: DECLARATION_TYPE })
.count

refundable = Finance::StatementLineItem
Expand All @@ -199,15 +201,15 @@ def previous_fill_level_for_uplift
.where(statement: statement.previous_statements)
.billable
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: "started" })
.where(participant_declarations: { declaration_type: "started", type: DECLARATION_TYPE })
.where("participant_declarations.sparsity_uplift = true OR participant_declarations.pupil_premium_uplift = true")
.count

refundable = Finance::StatementLineItem
.where(statement: statement.previous_statements)
.refundable
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: "started" })
.where(participant_declarations: { declaration_type: "started", type: DECLARATION_TYPE })
.where("participant_declarations.sparsity_uplift = true OR participant_declarations.pupil_premium_uplift = true")
.count

Expand All @@ -218,23 +220,23 @@ def current_billable_count_for_declaration_type(declaration_type)
statement
.billable_statement_line_items
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: })
.where(participant_declarations: { declaration_type:, type: DECLARATION_TYPE })
.count
end

def current_refundable_count_declaration_type(declaration_type)
statement
.refundable_statement_line_items
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: })
.where(participant_declarations: { declaration_type:, type: DECLARATION_TYPE })
.count
end

def current_billable_count_for_uplift
statement
.billable_statement_line_items
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: "started" })
.where(participant_declarations: { declaration_type: "started", type: DECLARATION_TYPE })
.where("participant_declarations.sparsity_uplift = true OR participant_declarations.pupil_premium_uplift = true")
.count
end
Expand All @@ -243,7 +245,7 @@ def current_refundable_count_for_uplift
statement
.refundable_statement_line_items
.joins(:participant_declaration)
.where(participant_declarations: { declaration_type: "started" })
.where(participant_declarations: { declaration_type: "started", type: DECLARATION_TYPE })
.where("participant_declarations.sparsity_uplift = true OR participant_declarations.pupil_premium_uplift = true")
.count
end
Expand Down
4 changes: 3 additions & 1 deletion app/services/record_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ def validates_billable_slot_available
def participant_declaration_class
if participant_profile.npq?
ParticipantDeclaration::NPQ
elsif participant_profile.mentor?
ParticipantDeclaration::Mentor
else
ParticipantDeclaration::ECF
ParticipantDeclaration::ECT
end
end

Expand Down
22 changes: 11 additions & 11 deletions spec/factories/participant_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
has_passed { false }
end

factory :ecf_participant_declaration, class: "ParticipantDeclaration::ECF" do
factory :ect_participant_declaration, class: ParticipantDeclaration::ECT do
type { "ParticipantDeclaration::ECT" }
cpd_lead_provider { create(:cpd_lead_provider, :with_lead_provider) }
course_identifier { "ecf-induction" }
participant_profile { create(:ect, *uplifts, *profile_traits, lead_provider: cpd_lead_provider.lead_provider, cohort:) }
end

factory :ect_participant_declaration, class: "ParticipantDeclaration::ECF" do
course_identifier { "ecf-induction" }
participant_profile { create(:ect, *uplifts, *profile_traits, lead_provider: cpd_lead_provider.lead_provider, cohort:) }
end

factory :mentor_participant_declaration, class: "ParticipantDeclaration::ECF" do
course_identifier { "ecf-mentor" }
participant_profile { create(:mentor, *uplifts, *profile_traits, lead_provider: cpd_lead_provider.lead_provider, cohort:) }
end
factory :mentor_participant_declaration, class: ParticipantDeclaration::Mentor do
type { "ParticipantDeclaration::Mentor" }
cpd_lead_provider { create(:cpd_lead_provider, :with_lead_provider) }
course_identifier { "ecf-mentor" }
participant_profile { create(:mentor, *uplifts, *profile_traits, lead_provider: cpd_lead_provider.lead_provider, cohort:) }
end

factory :npq_participant_declaration, class: "ParticipantDeclaration::NPQ" do
factory :npq_participant_declaration, class: ParticipantDeclaration::NPQ do
transient do
npq_course { create(:npq_course) }
school_urn {}
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/seeds/participant_declaration_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end
end

factory(:seed_ecf_participant_declaration, class: "ParticipantDeclaration::ECF") do
factory(:seed_ecf_participant_declaration, class: "ParticipantDeclaration::ECT") do
trait(:with_ecf_participant_profile) do
association(:participant_profile, factory: %i[seed_ect_participant_profile valid])
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/importers/clawbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe Importers::Clawbacks do
let(:csv) { Tempfile.new("data.csv") }
let(:path_to_csv) { csv.path }
let(:participant_declaration) { create(:ect_participant_declaration) }
let(:participant_declaration) { create(:ect_participant_declaration).reload }

subject { described_class.new(path_to_csv:) }

Expand Down

0 comments on commit af684e4

Please sign in to comment.