mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
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.
22 lines
431 B
Ruby
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
|