From 3aeb87debccdb3376d27e9431a71b7e6ddf35509 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 19 May 2020 20:48:40 +0100 Subject: [PATCH] Make it work with both relations and arrays --- lib/open_food_network/packing_report.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/open_food_network/packing_report.rb b/lib/open_food_network/packing_report.rb index 88a3582083..34c1e0e730 100644 --- a/lib/open_food_network/packing_report.rb +++ b/lib/open_food_network/packing_report.rb @@ -61,7 +61,7 @@ module OpenFoodNetwork proc { |_line_items| "" }, proc { |_line_items| I18n.t('admin.reports.total_items') }, proc { |_line_items| "" }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.to_a.sum(&:quantity) }, proc { |_line_items| "" }] }, { group_by: proc { |line_item| line_item.product.supplier }, sort_by: proc { |supplier| supplier.name } }, @@ -82,7 +82,7 @@ module OpenFoodNetwork proc { |_line_items| "" }, proc { |_line_items| I18n.t('admin.reports.total_items') }, proc { |_line_items| "" }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.to_a.sum(&:quantity) }, proc { |_line_items| "" }] }, { group_by: proc { |line_item| line_item.product }, sort_by: proc { |product| product.name } }, @@ -102,7 +102,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.product.supplier.name }, proc { |line_items| line_items.first.product.name }, proc { |line_items| line_items.first.full_name }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.to_a.sum(&:quantity) }, proc { |line_items| is_temperature_controlled?(line_items.first) }] else [ @@ -113,7 +113,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.order.bill_address.lastname }, proc { |line_items| line_items.first.product.name }, proc { |line_items| line_items.first.full_name }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.to_a.sum(&:quantity) }, proc { |line_items| is_temperature_controlled?(line_items.first) } ] end