From 0ae3ea63621a02a345ec6626e9f9884f00703489 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Wed, 22 Jan 2025 15:35:50 +0000 Subject: [PATCH] Move max topup amount to policy We'll be making topups availble on all polices so we don't want any policy specific logic in the topup. --- app/models/policies/levelling_up_premium_payments.rb | 4 ++++ app/models/topup.rb | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/policies/levelling_up_premium_payments.rb b/app/models/policies/levelling_up_premium_payments.rb index 1a6f81f769..2b6bc1e038 100644 --- a/app/models/policies/levelling_up_premium_payments.rb +++ b/app/models/policies/levelling_up_premium_payments.rb @@ -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 diff --git a/app/models/topup.rb b/app/models/topup.rb index c6c996dee6..fbea205f36 100644 --- a/app/models/topup.rb +++ b/app/models/topup.rb @@ -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)