mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-07 07:36:58 +00:00
Extract query object
This commit is contained in:
@@ -65,13 +65,7 @@ module Admin
|
||||
def collection
|
||||
return Customer.where("1=0") unless json_request? && params[:enterprise_id].present?
|
||||
|
||||
Customer.of(managed_enterprise_id).
|
||||
includes(:bill_address, :ship_address, user: :credit_cards).
|
||||
joins(:orders).
|
||||
merge(Spree::Order.complete.not_state(:canceled)).
|
||||
group("customers.id").
|
||||
select("customers.*").
|
||||
select("SUM(total - payment_total) AS balance_value")
|
||||
CustomersWithBalance.new(managed_enterprise_id).query
|
||||
end
|
||||
|
||||
def managed_enterprise_id
|
||||
|
||||
19
app/services/customers_with_balance.rb
Normal file
19
app/services/customers_with_balance.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class CustomersWithBalance
|
||||
def initialize(enterprise_id)
|
||||
@enterprise_id = enterprise_id
|
||||
end
|
||||
|
||||
def query
|
||||
Customer.of(enterprise_id).
|
||||
includes(:bill_address, :ship_address, user: :credit_cards).
|
||||
joins(:orders).
|
||||
merge(Spree::Order.complete.not_state(:canceled)).
|
||||
group("customers.id").
|
||||
select("customers.*").
|
||||
select("SUM(total - payment_total) AS balance_value")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :enterprise_id
|
||||
end
|
||||
Reference in New Issue
Block a user