From a31487a86d92d22aaad56845cf5344273eff6a74 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 23 Mar 2021 19:56:29 +0000 Subject: [PATCH] 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). --- app/models/spree/order.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 817a0d716b..556b8b0c13 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -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?