mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Reapply taxes at model level if order address changes
This should be done at the model level
This commit is contained in:
@@ -24,7 +24,6 @@ module Spree
|
||||
end
|
||||
|
||||
refresh_shipment_rates
|
||||
recalculate_taxes
|
||||
OrderWorkflow.new(@order).advance_to_payment
|
||||
|
||||
flash[:success] = Spree.t('customer_details_updated')
|
||||
@@ -52,13 +51,6 @@ module Spree
|
||||
@order.shipments.map(&:refresh_rates)
|
||||
end
|
||||
|
||||
def recalculate_taxes
|
||||
# If the order's address has been changed, the tax zone could be different,
|
||||
# which means a different set of tax rates might be applicable.
|
||||
@order.create_tax_charge!
|
||||
@order.update_totals_and_states
|
||||
end
|
||||
|
||||
def order_params
|
||||
params.require(:order).permit(
|
||||
:email,
|
||||
|
||||
@@ -108,6 +108,7 @@ module Spree
|
||||
before_save :update_payment_fees!, if: :complete?
|
||||
|
||||
after_create :create_tax_charge!
|
||||
after_save :reapply_tax_on_changed_address
|
||||
|
||||
after_save_commit DefaultAddressUpdater
|
||||
|
||||
@@ -580,6 +581,14 @@ module Spree
|
||||
|
||||
private
|
||||
|
||||
def reapply_tax_on_changed_address
|
||||
return if before_payment_state?
|
||||
return unless tax_address&.saved_changes?
|
||||
|
||||
create_tax_charge!
|
||||
update_totals_and_states
|
||||
end
|
||||
|
||||
def deliver_order_confirmation_email
|
||||
return if subscription.present?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user