mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Extract line_items_total from compute_order
This commit is contained in:
@@ -26,12 +26,6 @@ module Calculator
|
||||
|
||||
# Enable calculation of tax for enterprise fees with tax rates where included_in_price = false
|
||||
def compute_order(order)
|
||||
matched_line_items = order.line_items.select do |line_item|
|
||||
line_item.product.tax_category == rate.tax_category
|
||||
end
|
||||
|
||||
line_items_total = matched_line_items.sum(&:total)
|
||||
|
||||
calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(order.distributor,
|
||||
order.order_cycle)
|
||||
|
||||
@@ -54,11 +48,19 @@ module Calculator
|
||||
.select { |applicator| applicator.enterprise_fee.tax_category == rate.tax_category }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(order) }
|
||||
|
||||
[line_items_total, per_item_fees_total, per_order_fees_total].sum do |total|
|
||||
[line_items_total(order), per_item_fees_total, per_order_fees_total].sum do |total|
|
||||
round_to_two_places(total * rate.amount)
|
||||
end
|
||||
end
|
||||
|
||||
def line_items_total(order)
|
||||
matched_line_items = order.line_items.select do |line_item|
|
||||
line_item.product.tax_category == rate.tax_category
|
||||
end
|
||||
|
||||
matched_line_items.sum(&:total)
|
||||
end
|
||||
|
||||
def compute_line_item(line_item)
|
||||
if line_item.tax_category == rate.tax_category
|
||||
if rate.included_in_price
|
||||
|
||||
Reference in New Issue
Block a user