Fix problem in default_tax related to sum in active record

This commit is contained in:
Luis Ramos
2020-08-06 19:45:27 +01:00
parent 399fe2c01b
commit 9a9b455e66
4 changed files with 4 additions and 4 deletions

View File

@@ -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) }

View File

@@ -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

View File

@@ -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

View File

@@ -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