Files
openfoodnetwork/app/queries/complete_orders_with_balance.rb
Pau Perez cc9e3fe69b Replace double negation with proper list of states
We rely now on the exhaustive list of states an order can be in after
checkout. What made this all a bit more messy is that I made up the
"checkout" order state, likely mixing it from the payment model states.

This simplifies things quite a bit and gives meaningful names to things.
2021-01-20 18:34:31 +01:00

22 lines
431 B
Ruby

# frozen_string_literal: true
# Fetches complete orders of the specified user including their balance as a computed column
class CompleteOrdersWithBalance
def initialize(user)
@user = user
end
def query
OutstandingBalance.new(sorted_finalized_orders).query
end
private
def sorted_finalized_orders
@user.orders
.finalized
.select('spree_orders.*')
.order(completed_at: :desc)
end
end