mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user