Re-apply taxes in Admin::OrdersController#update

Ensures taxes are updated properly when hitting the "Update and Recalculate Fees" button on the order edit page.
This commit is contained in:
Matt-Yorkley
2021-04-07 15:01:24 +01:00
parent 43877f4e34
commit 0f5c39317a
2 changed files with 16 additions and 4 deletions

View File

@@ -37,6 +37,11 @@ module Spree
def update
@order.recreate_all_fees!
unless @order.cart?
@order.create_tax_charge!
@order.update_order!
end
unless order_params.present? && @order.update(order_params) && @order.line_items.present?
if @order.line_items.empty? && !params[:suppress_error_msg]
@order.errors.add(:line_items, Spree.t('errors.messages.blank'))

View File

@@ -58,12 +58,19 @@ describe Spree::Admin::OrdersController, type: :controller do
expect(response.status).to eq 302
end
it "updates distribution charges and redirects to order details page" do
expect_any_instance_of(Spree::Order).to receive(:recreate_all_fees!)
context "recalculating fees and taxes" do
before do
allow(Spree::Order).to receive_message_chain(:includes, :find_by!) { order }
end
spree_put :update, params
it "updates fees and taxes and redirects to order details page" do
expect(order).to receive(:recreate_all_fees!)
expect(order).to receive(:create_tax_charge!)
expect(response).to redirect_to spree.edit_admin_order_path(order)
spree_put :update, params
expect(response).to redirect_to spree.edit_admin_order_path(order)
end
end
context "recalculating enterprise fees" do