Skip to content

Commit

Permalink
Move max topup amount to policy
Browse files Browse the repository at this point in the history
We'll be making topups availble on all polices so we don't want any
policy specific logic in the topup.
  • Loading branch information
rjlynch committed Jan 23, 2025
1 parent 369a9c4 commit 0ae3ea6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/policies/levelling_up_premium_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,9 @@ def selectable_itt_years_for_claim_year(claim_year)
def closed?(claim_year)
claim_year > POLICY_END_YEAR
end

def max_topup_amount(claim)
Award.where(academic_year: claim.academic_year.to_s).maximum(:award_amount)
end
end
end
3 changes: 2 additions & 1 deletion app/models/topup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def teacher_reference_number
def award_amount_must_be_in_range
return unless award_amount.present?

max = Policies::LevellingUpPremiumPayments::Award.where(academic_year: claim.academic_year.to_s).maximum(:award_amount)
max = claim.policy.max_topup_amount(claim)

total_amount = claim.award_amount_with_topups + award_amount

unless total_amount.between?(1, max)
Expand Down

0 comments on commit 0ae3ea6

Please sign in to comment.