From 399fe2c01b5ffdb18fcf2488cc7aabc94bc5b7c7 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 19 May 2020 22:26:26 +0100 Subject: [PATCH] Make code work for relations and arrays --- app/mailers/producer_mailer.rb | 4 ++-- app/views/spree/orders/_bought.html.haml | 2 +- lib/open_food_network/xero_invoices_report.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 48f3c6a34d..5c61f2d0c8 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -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) diff --git a/app/views/spree/orders/_bought.html.haml b/app/views/spree/orders/_bought.html.haml index f7030b31a8..e9cee63e7c 100644 --- a/app/views/spree/orders/_bought.html.haml +++ b/app/views/spree/orders/_bought.html.haml @@ -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) diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index 2d6bc80f71..90a43e54c8 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -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)