Make it work with both relations and arrays

This commit is contained in:
Luis Ramos
2020-05-19 20:48:40 +01:00
parent 7b06fdd943
commit 3aeb87debc

View File

@@ -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