mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Converting all calls to ActiveRelation#sum to use a symbol with &
This is only applicable to database columns, if we are summing using a method in the model than the & is required!
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,7 +16,7 @@ module Api
|
||||
end
|
||||
|
||||
def item_count
|
||||
object.line_items.sum(&:quantity)
|
||||
object.line_items.sum(:quantity)
|
||||
end
|
||||
|
||||
def completed_at
|
||||
|
||||
@@ -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')`.
|
||||
#
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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| "" },
|
||||
|
||||
@@ -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| "" },
|
||||
|
||||
@@ -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| "" },
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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) },
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user