Merge pull request #4524 from Matt-Yorkley/packing_reports

Packing reports performance
This commit is contained in:
Luis Ramos
2019-12-02 17:32:52 +00:00
committed by GitHub
2 changed files with 9 additions and 7 deletions

View File

@@ -236,7 +236,8 @@ Spree::Admin::ReportsController.class_eval do
end
def suppliers_of_products_distributed_by(distributors)
distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq
distributors.map { |d| Spree::Product.in_distributor(d).includes(:supplier).all }.
flatten.map(&:supplier).uniq
end
# Load order cycles the current user has access to

View File

@@ -95,7 +95,7 @@ module OpenFoodNetwork
def columns
if is_by_customer?
[proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| customer_code(line_items.first.order.email) },
proc { |line_items| customer_code(line_items.first.order) },
proc { |line_items| line_items.first.order.bill_address.firstname },
proc { |line_items| line_items.first.order.bill_address.lastname },
proc { |line_items| line_items.first.product.supplier.name },
@@ -107,7 +107,7 @@ module OpenFoodNetwork
[
proc { |line_items| line_items.first.order.distributor.name },
proc { |line_items| line_items.first.product.supplier.name },
proc { |line_items| customer_code(line_items.first.order.email) },
proc { |line_items| customer_code(line_items.first.order) },
proc { |line_items| line_items.first.order.bill_address.firstname },
proc { |line_items| line_items.first.order.bill_address.lastname },
proc { |line_items| line_items.first.product.name },
@@ -121,8 +121,9 @@ module OpenFoodNetwork
private
def line_item_includes
[{ order: [:bill_address, :distributor],
variant: [{ option_values: :option_type }, { product: :supplier }] }]
[{ option_values: :option_type,
order: [:bill_address, :distributor, :customer],
variant: { product: [:supplier, :shipping_category] } }]
end
def order_permissions
@@ -142,8 +143,8 @@ module OpenFoodNetwork
params[:report_type] == "pack_by_customer"
end
def customer_code(email)
customer = Customer.where(email: email).first
def customer_code(order)
customer = order.customer
customer.nil? ? "" : customer.code
end