diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 9f21588ee6..72779dd4ec 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -18,7 +18,7 @@ module CheckoutHelper enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' && a.source_type != 'Spree::LineItem' } adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' && a.source_type != 'Spree::LineItem' } unless exclude.include? :admin_and_handling - adjustments << Spree::Adjustment.new(label: I18n.t(:orders_form_admin), amount: enterprise_fee_adjustments.sum(&:amount)) + adjustments << Spree::Adjustment.new(label: I18n.t(:orders_form_admin), amount: enterprise_fee_adjustments.sum(:amount)) end adjustments diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index cbe411fdeb..c2da5814d6 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -178,7 +178,7 @@ module Spree end def included_tax - adjustments.included_tax.sum(&:included_tax) + adjustments.included_tax.sum(:included_tax) end def tax_rates diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index c2a0a98582..3d844aa8e7 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -729,15 +729,15 @@ module Spree end def shipping_tax - adjustments(:reload).shipping.sum(&:included_tax) + adjustments(:reload).shipping.sum(:included_tax) end def enterprise_fee_tax - adjustments(:reload).enterprise_fee.sum(&:included_tax) + adjustments(:reload).enterprise_fee.sum(:included_tax) end def total_tax - (adjustments + price_adjustments).sum(&:included_tax) + (adjustments.to_a + price_adjustments.to_a).sum(&:included_tax) end def price_adjustments diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb index cbac0c00b4..427c222ea2 100644 --- a/app/serializers/api/order_serializer.rb +++ b/app/serializers/api/order_serializer.rb @@ -16,7 +16,7 @@ module Api end def item_count - object.line_items.sum(&:quantity) + object.line_items.sum(:quantity) end def completed_at diff --git a/app/services/order_adjustments_fetcher.rb b/app/services/order_adjustments_fetcher.rb index 560f04bdb1..9292fe8e91 100644 --- a/app/services/order_adjustments_fetcher.rb +++ b/app/services/order_adjustments_fetcher.rb @@ -1,7 +1,7 @@ # This class allows orders with eager-loaded adjustment objects to calculate various adjustment # types without triggering additional queries. # -# For example; `order.adjustments.shipping.sum(&:amount)` would normally trigger a new query +# For example; `order.adjustments.shipping.sum(:amount)` would normally trigger a new query # regardless of whether or not adjustments have been preloaded, as `#shipping` is an adjustment # scope, eg; `scope :shipping, where(originator_type: 'Spree::ShippingMethod')`. # diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index cc78f43ecd..8acda45749 100644 --- a/app/views/producer_mailer/order_cycle_report.html.haml +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -37,13 +37,13 @@ %td #{raw(product_and_full_name)} %td.text-right - #{line_items.sum(&:quantity)} + #{line_items.sum(:quantity)} %td.text-right #{line_items.first.single_money} %td.text-right #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency) } %td.tax.text-right - #{Spree::Money.new(line_items.sum(&:included_tax), currency: line_items.first.currency) } + #{Spree::Money.new(line_items.sum(:included_tax), currency: line_items.first.currency) } %tr.total-row %td %td diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index c322c3cac5..4de8b60808 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -13,7 +13,7 @@ Orders summary = t :producer_mail_order_text \ - @grouped_line_items.each_pair do |product_and_full_name, line_items| - #{line_items.first.variant.sku} - #{raw(line_items.first.product.supplier.name)} - #{raw(product_and_full_name)} (QTY: #{line_items.sum(&:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} + #{line_items.first.variant.sku} - #{raw(line_items.first.product.supplier.name)} - #{raw(product_and_full_name)} (QTY: #{line_items.sum(:quantity)}) @ #{line_items.first.single_money} = #{Spree::Money.new(line_items.sum(&:total), currency: line_items.first.currency)} \ \ #{t :total}: #{@total} diff --git a/lib/open_food_network/group_buy_report.rb b/lib/open_food_network/group_buy_report.rb index 2cd4f23c20..45c9c9dbcd 100644 --- a/lib/open_food_network/group_buy_report.rb +++ b/lib/open_food_network/group_buy_report.rb @@ -38,7 +38,7 @@ module OpenFoodNetwork # Cycle thorugh variant of a product variant_groups = line_items_by_product.group_by(&:variant) variant_groups.each do |variant, line_items_by_variant| - sum_quantities = line_items_by_variant.sum(&:quantity) + sum_quantities = line_items_by_variant.sum(:quantity) sum_max_quantities = line_items_by_variant.sum { |li| li.max_quantity || 0 } variants_and_quantities << GroupBuyVariantRow.new(variant, sum_quantities, sum_max_quantities) end diff --git a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb b/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb index 3edbd71cf7..0ea53af020 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb @@ -134,7 +134,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.variant.product.name }, proc { |line_items| line_items.first.variant.full_name }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.sum(:quantity) }, proc { |line_items| line_items.sum(&:amount) }, proc { |line_items| line_items.sum(&:amount_with_adjustments) }, proc { |_line_items| "" }, diff --git a/lib/open_food_network/orders_and_fulfillments_report/default_report.rb b/lib/open_food_network/orders_and_fulfillments_report/default_report.rb index 4f59edd4bf..a503be84a0 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/default_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report/default_report.rb @@ -45,7 +45,7 @@ module OpenFoodNetwork supplier_name, product_name, line_items_name, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.sum(:quantity) }, proc { |line_items| line_items.first.price }, proc { |line_items| line_items.sum { |li| li.quantity * li.price } }, proc { |_line_items| "" }, diff --git a/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb b/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb index 8e3c810045..cfb1a1f3f9 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb @@ -59,7 +59,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.variant.product.supplier.name }, proc { |line_items| line_items.first.variant.product.name }, proc { |line_items| line_items.first.variant.full_name }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.sum(:quantity) }, proc { |line_items| line_items.first.price }, proc { |line_items| line_items.sum(&:amount) }, proc { |_line_items| "" }, diff --git a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb index 42c3523e00..cddc962f49 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb @@ -60,7 +60,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.variant.product.name }, proc { |line_items| line_items.first.variant.full_name }, proc { |line_items| line_items.first.order.distributor.name }, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.sum(:quantity) }, proc { |line_items| line_items.first.price }, proc { |line_items| line_items.sum(&:amount) }, proc { |_line_items| I18n.t(:report_header_shipping_method) } diff --git a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb index 09755adb1b..3029cf19b3 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb @@ -44,7 +44,7 @@ module OpenFoodNetwork supplier_name, product_name, line_items_name, - proc { |line_items| line_items.sum(&:quantity) }, + proc { |line_items| line_items.sum(:quantity) }, proc { |line_items| total_units(line_items) }, proc { |line_items| line_items.first.price }, proc { |line_items| line_items.sum(&:amount) }, diff --git a/lib/open_food_network/payments_report.rb b/lib/open_food_network/payments_report.rb index 3c2fbbd24b..7cfc6342f4 100644 --- a/lib/open_food_network/payments_report.rb +++ b/lib/open_food_network/payments_report.rb @@ -92,28 +92,28 @@ module OpenFoodNetwork [proc { |payments| payments.first.order.payment_state }, proc { |payments| payments.first.order.distributor.name }, proc { |payments| payments.first.payment_method.name }, - proc { |payments| payments.sum(&:amount) }] + proc { |payments| payments.sum(:amount) }] when "itemised_payment_totals" [proc { |orders| orders.first.payment_state }, proc { |orders| orders.first.distributor.name }, - proc { |orders| orders.sum(&:item_total) }, + proc { |orders| orders.sum(:item_total) }, proc { |orders| orders.sum(&:ship_total) }, proc { |orders| orders.sum(&:outstanding_balance) }, - proc { |orders| orders.sum(&:total) }] + proc { |orders| orders.sum(:total) }] when "payment_totals" [proc { |orders| orders.first.payment_state }, proc { |orders| orders.first.distributor.name }, - proc { |orders| orders.sum(&:item_total) }, + proc { |orders| orders.sum(:item_total) }, proc { |orders| orders.sum(&:ship_total) }, - proc { |orders| orders.sum(&:total) }, - proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "EFT") }.sum(&:amount) } }, - proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "PayPal") }.sum(&:amount) } }, + proc { |orders| orders.sum(:total) }, + proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "EFT") }.sum(:amount) } }, + proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "PayPal") }.sum(:amount) } }, proc { |orders| orders.sum(&:outstanding_balance) }] else [proc { |payments| payments.first.order.payment_state }, proc { |payments| payments.first.order.distributor.name }, proc { |payments| payments.first.payment_method.name }, - proc { |payments| payments.sum(&:amount) }] + proc { |payments| payments.sum(:amount) }] end end end diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 458b4523af..d7a8863b28 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -101,7 +101,7 @@ module OpenFoodNetwork end def tax_included_in(line_item) - line_item.adjustments.sum(&:included_tax) + line_item.adjustments.sum(:included_tax) end def shipment_inc_vat diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index 90a43e54c8..2821cbdb98 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -188,32 +188,32 @@ module OpenFoodNetwork end def total_untaxable_fees(order) - order.adjustments.enterprise_fee.without_tax.sum(&:amount) + order.adjustments.enterprise_fee.without_tax.sum(:amount) end def total_taxable_fees(order) - order.adjustments.enterprise_fee.with_tax.sum(&:amount) + order.adjustments.enterprise_fee.with_tax.sum(:amount) end def total_shipping(order) - order.adjustments.shipping.sum(&:amount) + order.adjustments.shipping.sum(:amount) end def total_transaction(order) - order.adjustments.payment_fee.sum(&:amount) + order.adjustments.payment_fee.sum(:amount) end def tax_on_shipping_s(order) - tax_on_shipping = order.adjustments.shipping.sum(&:included_tax) > 0 + tax_on_shipping = order.adjustments.shipping.sum(:included_tax) > 0 tax_on_shipping ? I18n.t(:report_header_gst_on_income) : I18n.t(:report_header_gst_free_income) end def total_untaxable_admin_adjustments(order) - order.adjustments.admin.without_tax.sum(&:amount) + order.adjustments.admin.without_tax.sum(:amount) end def total_taxable_admin_adjustments(order) - order.adjustments.admin.with_tax.sum(&:amount) + order.adjustments.admin.with_tax.sum(:amount) end def detail? diff --git a/spec/models/concerns/variant_stock_spec.rb b/spec/models/concerns/variant_stock_spec.rb index ef173bd5f3..5bdb119047 100644 --- a/spec/models/concerns/variant_stock_spec.rb +++ b/spec/models/concerns/variant_stock_spec.rb @@ -26,7 +26,7 @@ describe VariantStock do end it 'returns the total items in stock anyway' do - expect(variant.on_hand).to eq(variant.stock_items.sum(&:count_on_hand)) + expect(variant.on_hand).to eq(variant.stock_items.sum(:count_on_hand)) end end @@ -39,7 +39,7 @@ describe VariantStock do it 'returns the total items in stock' do expect(variant.on_hand) - .to eq(variant.stock_items.sum(&:count_on_hand)) + .to eq(variant.stock_items.sum(:count_on_hand)) end end end