Clear any legacy taxes when applying tax to an order

#create_tax_charge! adds tax (adjustments) to all taxable items on an order. If an order order has legacy taxes (lump-sum tax adjustments on the order object), we remove them here before re-applying taxes (using the new setup).
This commit is contained in:
Matt-Yorkley
2021-03-23 19:56:29 +00:00
parent 84a40e6ae0
commit a31487a86d

View File

@@ -293,6 +293,8 @@ module Spree
# Creates new tax charges if there are any applicable rates. If prices already
# include taxes then price adjustments are created instead.
def create_tax_charge!
clear_legacy_taxes!
Spree::TaxRate.adjust(self, line_items)
Spree::TaxRate.adjust(self, shipments) if shipments.any?
Spree::TaxRate.adjust(self, all_adjustments.enterprise_fee)
@@ -592,6 +594,13 @@ module Spree
@fee_handler ||= OrderFeesHandler.new(self)
end
def clear_legacy_taxes!
# For instances that use additional taxes, old orders can have taxes recorded in
# lump-sum amounts per-order. We clear them here before re-applying the order's taxes,
# which will now be applied per-item.
adjustments.tax.additional.delete_all
end
def process_each_payment
raise Core::GatewayError, Spree.t(:no_pending_payments) if pending_payments.empty?