Bug fixes to Order Cycle Reports

This commit is contained in:
Lynne Davis
2016-02-16 17:47:51 +00:00
committed by Rob Harrington
parent 6c5aaef86e
commit d844dc8e1b
2 changed files with 14 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ module OpenFoodNetwork
end
def search
Spree::Order.complete.where("spree_orders.state != ?", :canceled).distributed_by_user(@user).managed_by(@user).search(params[:q])
Spree::Order.complete.distributed_by_user(@user).managed_by(@user).search(params[:q])
end
def orders
@@ -50,7 +50,7 @@ module OpenFoodNetwork
order.shipping_method.andand.name,
order.payments.first.andand.payment_method.andand.name,
order.payments.first.amount,
OpenFoodNetwork::UserBalanceCalculator.new(order.user, order.distributor).balance
OpenFoodNetwork::UserBalanceCalculator.new(order.email, order.distributor).balance
]
end
@@ -67,23 +67,23 @@ module OpenFoodNetwork
order.shipping_method.andand.name,
order.payments.first.andand.payment_method.andand.name,
order.payments.first.amount,
OpenFoodNetwork::UserBalanceCalculator.new(order.user, order.distributor).balance,
OpenFoodNetwork::UserBalanceCalculator.new(order.email, order.distributor).balance,
has_temperature_controlled_items?(order),
order.special_instructions
]
end
def filter_to_payment_method(orders)
if params[:payment_method_name].present?
orders.with_payment_method_name(params[:payment_method_name])
if params[:payment_method_in].present?
orders.with_payment_method_name(params[:payment_method_in])
else
orders
end
end
def filter_to_shipping_method(orders)
if params[:shipping_method_name].present?
orders.joins(:shipping_method).where("spree_shipping_methods.name = ?", params[:shipping_method_name])
if params[:shipping_method_in].present?
orders.joins(:shipping_method).where("spree_shipping_methods.name = ?", params[:shipping_method_in])
else
orders
end

View File

@@ -1,19 +1,19 @@
module OpenFoodNetwork
class UserBalanceCalculator
def initialize(user, distributor)
@user = user
def initialize(email, distributor)
@email = email
@distributor = distributor
end
def balance
payment_total - order_total
payment_total - completed_order_total
end
private
def order_total
orders.sum &:total
def completed_order_total
orders.complete.sum &:total
end
def payment_total
@@ -22,11 +22,11 @@ module OpenFoodNetwork
def orders
Spree::Order.where(distributor_id: @distributor, user_id: @user)
Spree::Order.where(distributor_id: @distributor, email: @email)
end
def payments
Spree::Payment.where(order_id: orders)
Spree::Payment.where(order_id: orders, state: "completed")
end
end
end