Adapt current tax setup to work with shipment taxes

This is a temporary step...
This commit is contained in:
Matt-Yorkley
2021-02-07 23:17:11 +00:00
parent 7425ad5c4a
commit 7e0aad7c7e
2 changed files with 9 additions and 2 deletions

View File

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

View File

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