mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Extract most everything to private methods - neatly groups concerns together
This commit is contained in:
@@ -4,14 +4,29 @@ module OpenFoodNetwork
|
||||
@user = user
|
||||
@distributor = distributor
|
||||
end
|
||||
|
||||
|
||||
def balance
|
||||
orders = Spree::Order.where(distributor_id: @distributor, user_id: @user)
|
||||
order_total = orders.sum &:total
|
||||
|
||||
payments = Spree::Payment.where(order_id: orders)
|
||||
payment_total = payments.sum &:amount
|
||||
payment_total - order_total
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def order_total
|
||||
orders.sum &:total
|
||||
end
|
||||
|
||||
def payment_total
|
||||
payments.sum &:amount
|
||||
end
|
||||
|
||||
|
||||
def orders
|
||||
Spree::Order.where(distributor_id: @distributor, user_id: @user)
|
||||
end
|
||||
|
||||
def payments
|
||||
Spree::Payment.where(order_id: orders)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,6 +39,6 @@ module OpenFoodNetwork
|
||||
UserBalanceCalculator.new(user2, hub1).balance.should == 10
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user