mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Fix some rubocop issues
This commit is contained in:
@@ -33,27 +33,28 @@ module Spree
|
||||
|
||||
line_items_total = matched_line_items.sum(&:total)
|
||||
|
||||
# Added this line
|
||||
calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(order.distributor, order.order_cycle)
|
||||
calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(order.distributor,
|
||||
order.order_cycle)
|
||||
|
||||
# Added this block, finds relevant fees for each line_item, calculates the tax on them, and returns the total tax
|
||||
# Finds relevant fees for each line_item,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
per_item_fees_total = order.line_items.sum do |line_item|
|
||||
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
|
||||
.select { |applicator|
|
||||
(!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) ||
|
||||
(applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
|
||||
(!applicator.enterprise_fee.inherits_tax_category &&
|
||||
applicator.enterprise_fee.tax_category == rate.tax_category) ||
|
||||
(applicator.enterprise_fee.inherits_tax_category &&
|
||||
line_item.product.tax_category == rate.tax_category)
|
||||
}
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
|
||||
end
|
||||
|
||||
# Added this block, finds relevant fees for whole order, calculates the tax on them, and returns the total tax
|
||||
# Finds relevant fees for whole order,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
per_order_fees_total = calculator.per_order_enterprise_fee_applicators_for(order)
|
||||
.select { |applicator| applicator.enterprise_fee.tax_category == rate.tax_category }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(order) }
|
||||
|
||||
# round_to_two_places(line_items_total * rate.amount) # Removed this line
|
||||
|
||||
# Added this block
|
||||
[line_items_total, per_item_fees_total, per_order_fees_total].sum do |total|
|
||||
round_to_two_places(total * rate.amount)
|
||||
end
|
||||
@@ -72,7 +73,7 @@ module Spree
|
||||
end
|
||||
|
||||
def round_to_two_places(amount)
|
||||
BigDecimal.new(amount.to_s).round(2, BigDecimal::ROUND_HALF_UP)
|
||||
BigDecimal(amount.to_s).round(2, BigDecimal::ROUND_HALF_UP)
|
||||
end
|
||||
|
||||
def deduced_total_by_rate(total, rate)
|
||||
|
||||
@@ -28,8 +28,9 @@ module Spree
|
||||
sum = 0
|
||||
max = preferred_max_items.to_i
|
||||
items_count = line_items_for(object).map(&:quantity).sum
|
||||
|
||||
# check max value to avoid divide by 0 errors
|
||||
unless max == 0
|
||||
unless max.zero?
|
||||
if items_count > max
|
||||
sum += (max - 1) * preferred_additional_item.to_f + preferred_first_item.to_f
|
||||
elsif items_count <= max
|
||||
|
||||
Reference in New Issue
Block a user