mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Allowing Order Management Report to filter by multiple payment / shipping methods at once
Also switched to using id rather than name to filter
This commit is contained in:
@@ -11,11 +11,17 @@ module Spree
|
||||
end
|
||||
|
||||
def report_payment_method_options(orders)
|
||||
orders.map { |o| o.payments.first.payment_method.andand.name }.uniq
|
||||
orders.map do |o|
|
||||
pm = o.payments.first.payment_method
|
||||
[pm.andand.name, pm.andand.id]
|
||||
end.uniq
|
||||
end
|
||||
|
||||
def report_shipping_method_options(orders)
|
||||
orders.map { |o| o.shipping_method.andand.name }.uniq
|
||||
orders.map do |o|
|
||||
sm = o.shipping_method
|
||||
[sm.andand.name, sm.andand.id]
|
||||
end.uniq
|
||||
end
|
||||
|
||||
def xero_report_types
|
||||
|
||||
@@ -31,7 +31,7 @@ module OpenFoodNetwork
|
||||
ba.phone,
|
||||
order.distributor.andand.name,
|
||||
[da.andand.address1, da.andand.address2, da.andand.city].join(" "),
|
||||
order.shipping_method.andand.name
|
||||
order.shipping_method.andand.name
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -78,4 +78,3 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def search
|
||||
Spree::Order.complete.not_state(:canceled).distributed_by_user(@user).managed_by(@user).search(params[:q])
|
||||
Spree::Order.complete.where("spree_orders.state != ?", :canceled).distributed_by_user(@user).managed_by(@user).search(params[:q])
|
||||
end
|
||||
|
||||
def orders
|
||||
@@ -75,7 +75,7 @@ module OpenFoodNetwork
|
||||
|
||||
def filter_to_payment_method(orders)
|
||||
if params[:payment_method_in].present?
|
||||
orders.with_payment_method_name(params[:payment_method_in])
|
||||
orders.joins(payments: :payment_method).where(spree_payments: { payment_method_id: params[:payment_method_in]})
|
||||
else
|
||||
orders
|
||||
end
|
||||
@@ -83,7 +83,7 @@ module OpenFoodNetwork
|
||||
|
||||
def filter_to_shipping_method(orders)
|
||||
if params[:shipping_method_in].present?
|
||||
orders.joins(:shipping_method).where("spree_shipping_methods.name = ?", params[:shipping_method_in])
|
||||
orders.joins(:shipping_method).where(shipping_method_id: params[:shipping_method_in])
|
||||
else
|
||||
orders
|
||||
end
|
||||
|
||||
@@ -86,19 +86,23 @@ module OpenFoodNetwork
|
||||
|
||||
it "filters to a payment method" do
|
||||
pm2 = create(:payment_method, name: "PM2")
|
||||
order2 = create(:order)
|
||||
payment2 = create(:payment, order: order2, payment_method: pm2)
|
||||
pm3 = create(:payment_method, name: "PM3")
|
||||
order2 = create(:order, payments: [create(:payment, payment_method: pm2)])
|
||||
order3 = create(:order, payments: [create(:payment, payment_method: pm3)])
|
||||
# payment2 = create(:payment, order: order2, payment_method: pm2)
|
||||
|
||||
subject.stub(:params).and_return(payment_method_in: pm1.name)
|
||||
subject.filter(orders).should == [order1]
|
||||
subject.stub(:params).and_return(payment_method_in: [pm1.id, pm3.id] )
|
||||
subject.filter(orders).should == [order1, order3]
|
||||
end
|
||||
|
||||
it "filters to a shipping method" do
|
||||
sm2 = create(:shipping_method, name: "ship2")
|
||||
sm3 = create(:shipping_method, name: "ship3")
|
||||
order2 = create(:order, shipping_method: sm2)
|
||||
order3 = create(:order, shipping_method: sm3)
|
||||
|
||||
subject.stub(:params).and_return(shipping_method_in: sm1.name)
|
||||
subject.filter(orders).should == [order1]
|
||||
subject.stub(:params).and_return(shipping_method_in: [sm1.id, sm3.id])
|
||||
subject.filter(orders).should == [order1, order3]
|
||||
end
|
||||
|
||||
it "should do all the filters at once" do
|
||||
|
||||
Reference in New Issue
Block a user