diff --git a/app/models/participant_profile/ect.rb b/app/models/participant_profile/ect.rb index 4a130759c78..7a944a81fc9 100644 --- a/app/models/participant_profile/ect.rb +++ b/app/models/participant_profile/ect.rb @@ -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) } diff --git a/app/models/participant_profile/mentor.rb b/app/models/participant_profile/mentor.rb index 9042918ab72..d4603908c25 100644 --- a/app/models/participant_profile/mentor.rb +++ b/app/models/participant_profile/mentor.rb @@ -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", diff --git a/app/services/finance/ecf/assurance_report/query.rb b/app/services/finance/ecf/assurance_report/query.rb index e703830d658..3024454194a 100644 --- a/app/services/finance/ecf/assurance_report/query.rb +++ b/app/services/finance/ecf/assurance_report/query.rb @@ -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 @@ -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 diff --git a/app/services/finance/ecf/output_calculator.rb b/app/services/finance/ecf/output_calculator.rb index 21dcae98f2e..d982b9ba112 100644 --- a/app/services/finance/ecf/output_calculator.rb +++ b/app/services/finance/ecf/output_calculator.rb @@ -5,6 +5,8 @@ module ECF class OutputCalculator attr_reader :statement + DECLARATION_TYPE = "ParticipantDeclaration::ECT" + def initialize(statement:) @statement = statement end @@ -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 @@ -199,7 +201,7 @@ 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 @@ -207,7 +209,7 @@ def previous_fill_level_for_uplift .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 @@ -218,7 +220,7 @@ 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 @@ -226,7 +228,7 @@ 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 @@ -234,7 +236,7 @@ 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 @@ -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 diff --git a/app/services/record_declaration.rb b/app/services/record_declaration.rb index 695aa4eee06..f6d43d138c1 100644 --- a/app/services/record_declaration.rb +++ b/app/services/record_declaration.rb @@ -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 diff --git a/spec/factories/participant_declaration.rb b/spec/factories/participant_declaration.rb index 11b29c86f77..49d04bab02c 100644 --- a/spec/factories/participant_declaration.rb +++ b/spec/factories/participant_declaration.rb @@ -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 {} diff --git a/spec/factories/seeds/participant_declaration_factory.rb b/spec/factories/seeds/participant_declaration_factory.rb index b9d9ada8b7c..238ed76b1d4 100644 --- a/spec/factories/seeds/participant_declaration_factory.rb +++ b/spec/factories/seeds/participant_declaration_factory.rb @@ -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 diff --git a/spec/services/importers/clawbacks_spec.rb b/spec/services/importers/clawbacks_spec.rb index 82d2e2c3e81..2b0dc1bcfb8 100644 --- a/spec/services/importers/clawbacks_spec.rb +++ b/spec/services/importers/clawbacks_spec.rb @@ -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:) }