mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix problem in default_tax related to sum in active record
This commit is contained in:
@@ -49,7 +49,7 @@ module Calculator
|
||||
# Finds relevant fees for each line_item,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
def per_item_fees_total(order, calculator)
|
||||
order.line_items.sum do |line_item|
|
||||
order.line_items.to_a.sum do |line_item|
|
||||
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
|
||||
.select { |applicator| applicable_rate?(applicator, line_item) }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
|
||||
|
||||
@@ -18,7 +18,7 @@ class Calculator::FlatPercentPerItem < Spree::Calculator
|
||||
end
|
||||
|
||||
def compute(object)
|
||||
line_items_for(object).sum do |li|
|
||||
line_items_for(object).to_a.sum do |li|
|
||||
unless li.price.present? && li.quantity.present?
|
||||
raise ArgumentError, "object must respond to #price and #quantity"
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ module Calculator
|
||||
private
|
||||
|
||||
def total_weight(line_items)
|
||||
line_items.sum do |line_item|
|
||||
line_items.to_a.sum do |line_item|
|
||||
line_item_weight(line_item)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,7 +133,7 @@ feature '
|
||||
expect(page).to have_selector "a.view-variants", count: 1
|
||||
all("a.view-variants").each(&:click)
|
||||
|
||||
expect(page).to have_selector "span[name='on_hand']", text: p1.variants.sum(&:on_hand).to_s
|
||||
expect(page).to have_selector "span[name='on_hand']", text: p1.variants.to_a.sum(&:on_hand).to_s
|
||||
expect(page).to have_field "variant_on_hand", with: "15"
|
||||
expect(page).to have_field "variant_on_hand", with: "6"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user