Make code work for relations and arrays

This commit is contained in:
Luis Ramos
2020-05-19 22:26:26 +01:00
parent 3aeb87debc
commit 399fe2c01b
3 changed files with 5 additions and 5 deletions

View File

@@ -60,11 +60,11 @@ class ProducerMailer < Spree::BaseMailer
end
def total_from_line_items(line_items)
Spree::Money.new line_items.sum(&:total)
Spree::Money.new line_items.to_a.sum(&:total)
end
def tax_total_from_line_items(line_items)
Spree::Money.new line_items.sum(&:included_tax)
Spree::Money.new line_items.to_a.sum(&:included_tax)
end
# This hack makes ActiveRecord skip the default_scope (deleted_at IS NULL)

View File

@@ -3,7 +3,7 @@
%td.toggle-bought{ colspan: 2, ng: { click: 'showBought=!showBought' } }
%h5.brick
%i{ ng: { class: "{ 'ofn-i_007-caret-right': !showBought, 'ofn-i_005-caret-down': showBought}"} }
= t(:orders_bought_items_notice, count: @order.finalised_line_items.sum(&:quantity))
= t(:orders_bought_items_notice, count: @order.finalised_line_items.to_a.sum(&:quantity))
%td.text-right{ colspan: 3 }
%a.edit-finalised.button.radius.expand.small{ href: changeable_orders_link_path, ng: { class: "{secondary: !showBought, primary: showBought}" } }
= t(:orders_bought_edit_button)

View File

@@ -180,11 +180,11 @@ module OpenFoodNetwork
end
def total_untaxable_products(order)
order.line_items.without_tax.sum(&:amount)
order.line_items.without_tax.to_a.sum(&:amount)
end
def total_taxable_products(order)
order.line_items.with_tax.sum(&:amount)
order.line_items.with_tax.to_a.sum(&:amount)
end
def total_untaxable_fees(order)