From 932d571d2ce2e763a932df5f72e5f93ad21e9eae Mon Sep 17 00:00:00 2001 From: Lynne Davis Date: Wed, 12 Nov 2014 11:47:26 +0000 Subject: [PATCH] 266: Updating to incorporate Rohans suggestions. Searching on payment method name rather than id --- app/helpers/spree/reports_helper.rb | 12 +++++------- app/models/spree/order_decorator.rb | 6 ++++++ .../admin/reports/order_cycle_management.html.haml | 4 ++-- .../order_cycle_management_report.rb | 5 ++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/helpers/spree/reports_helper.rb b/app/helpers/spree/reports_helper.rb index 0378e7db46..5854ede743 100644 --- a/app/helpers/spree/reports_helper.rb +++ b/app/helpers/spree/reports_helper.rb @@ -13,14 +13,12 @@ module Spree #I don't like that this is done in two loops, but redundant list entries # were created otherwise... def report_payment_method_options(orders) - payment_method_list = {} - orders.map do |o| - payment_method_name = o.payments.first.payment_method.andand.name - payment_method_id = o.payments.first.payment_method.andand.id - payment_method_list[payment_method_name] = payment_method_id + payment_method_list = [] + orders.map do |o| + payment_method_list << o.payments.first.payment_method.andand.name end - payment_method_list.each do |key, value| - [ "#{value}".html_safe, key] + payment_method_list.uniq.each do |pm| + [ "#{pm}".html_safe, pm] end end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index fcc6054f3b..228410a116 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -66,6 +66,12 @@ Spree::Order.class_eval do where("state != ?", state) } + scope :with_payment_method_name, lambda { |payment_method_name| + joins(:payments => :payment_method). + where('spree_payment_methods.name = ?', payment_method_name). + select('DISTINCT spree_orders.*') + } + # -- Methods def products_available_from_new_distribution diff --git a/app/views/spree/admin/reports/order_cycle_management.html.haml b/app/views/spree/admin/reports/order_cycle_management.html.haml index a88e55ddde..a40281e255 100644 --- a/app/views/spree/admin/reports/order_cycle_management.html.haml +++ b/app/views/spree/admin/reports/order_cycle_management.html.haml @@ -9,8 +9,8 @@ = label_tag nil, "Payment Methods (hold Ctrl to select multiple payment methods)" %br - = select_tag(:payment_method_id, - options_for_select(report_payment_method_options(@orders), params[:payment_method_id]), + = select_tag(:payment_method_name, + options_for_select(report_payment_method_options(@orders), params[:payment_method_name]), multiple: true, include_blank: true) %br %br diff --git a/lib/open_food_network/order_cycle_management_report.rb b/lib/open_food_network/order_cycle_management_report.rb index 70c5de8f29..3208ab2d33 100644 --- a/lib/open_food_network/order_cycle_management_report.rb +++ b/lib/open_food_network/order_cycle_management_report.rb @@ -43,9 +43,8 @@ module OpenFoodNetwork end def filter_to_payment_method (orders) - if params.has_key? (:payment_method_id) - orders.joins(:payments) - .where(:spree_payments => {:payment_method_id => params[:payment_method_id]} ) + if params.has_key? (:payment_method_name) + orders.with_payment_method_name(params[:payment_method_name]) else orders end