Skip to content

Commit

Permalink
Use latest_per_pfmp scope and in_state
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Oct 25, 2024
1 parent 5800ab3 commit 16a1adc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/facades/classes_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ def nb_pfmps(class_id, state)
pfmps_by_classe_and_state.dig(class_id, state.to_s) || 0
end

def nb_payment_requests(classe, states)
count = 0
classe.pfmps.each do |pfmp|
p_r = pfmp.latest_payment_request
count += 1 if p_r.present? && states.include?(p_r.current_state.to_sym)
end
count
def nb_payment_requests(class_id, states)
ASP::PaymentRequest.latest_per_pfmp
.joins(pfmp: { schooling: :classe })
.where(classes: { id: class_id })
.in_state(states)
.count
end

private
Expand Down

0 comments on commit 16a1adc

Please sign in to comment.