Skip to content

Commit

Permalink
Remove MAXIMUM_CLAIMABLE_HOURS, refactor valid_mentor_training_hours?
Browse files Browse the repository at this point in the history
Now that we have the Claims::TrainingAllowance class we're able to rely on the `remaining_hours` method for this calculation, which allows us to move all of the logic for calculating training allowances to this single source of truth.
  • Loading branch information
Kizr authored and ollietreend committed Oct 7, 2024
1 parent dbc119d commit d527986
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions app/models/claims/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# fk_rails_... (school_id => schools.id)
#
class Claims::Claim < ApplicationRecord
MAXIMUM_CLAIMABLE_HOURS = 20
audited
has_associated_audits

Expand Down Expand Up @@ -80,14 +79,10 @@ class Claims::Claim < ApplicationRecord
delegate :name, to: :academic_year, prefix: true, allow_nil: true

def valid_mentor_training_hours?
mentor_trainings_without_current_claim = Claims::MentorTraining.joins(:claim)
.merge(Claims::Claim.active).where(
mentor_id: mentor_trainings.select(:mentor_id),
provider_id:,
).where.not(claim_id: [id, previous_revision_id])
grouped_trainings = [*mentor_trainings, *mentor_trainings_without_current_claim].group_by { [_1.mentor_id, _1.provider_id] }

grouped_trainings.transform_values { _1.sum(&:hours_completed) }.values.all? { _1 <= MAXIMUM_CLAIMABLE_HOURS }
mentors.all? do |mentor|
training_allowance = Claims::TrainingAllowance.new(mentor:, provider:, academic_year:)
training_allowance.remaining_hours >= 0
end
end

def submitted_on
Expand Down

0 comments on commit d527986

Please sign in to comment.