mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Adapt current tax setup to work with shipment taxes
This is a temporary step...
This commit is contained in:
@@ -33,6 +33,7 @@ module Calculator
|
||||
|
||||
[
|
||||
line_items_total(order),
|
||||
shipments_total(order),
|
||||
per_item_fees_total(order, calculator),
|
||||
per_order_fees_total(order, calculator)
|
||||
].sum do |total|
|
||||
@@ -48,6 +49,12 @@ module Calculator
|
||||
matched_line_items.sum(&:total)
|
||||
end
|
||||
|
||||
def shipments_total(order)
|
||||
order.shipments.select do |shipment|
|
||||
shipment.tax_category == rate.tax_category
|
||||
end.sum(&:cost)
|
||||
end
|
||||
|
||||
# Finds relevant fees for each line_item,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
def per_item_fees_total(order, calculator)
|
||||
|
||||
@@ -36,8 +36,7 @@ module Spree
|
||||
end
|
||||
|
||||
def self.adjust(order)
|
||||
order.adjustments.tax.destroy_all
|
||||
order.line_item_adjustments.where(originator_type: 'Spree::TaxRate').destroy_all
|
||||
order.all_adjustments.tax.destroy_all
|
||||
|
||||
match(order).each do |rate|
|
||||
rate.adjust(order)
|
||||
@@ -63,6 +62,7 @@ module Spree
|
||||
if included_in_price
|
||||
if default_zone_or_zone_match? order
|
||||
order.line_items.each { |line_item| create_adjustment(label, line_item, line_item) }
|
||||
order.shipments.each { |shipment| create_adjustment(label, shipment, shipment) }
|
||||
else
|
||||
amount = -1 * calculator.compute(order)
|
||||
label = Spree.t(:refund) + label
|
||||
|
||||
Reference in New Issue
Block a user