Merge pull request #7112 from Matt-Yorkley/admin-adjustments-controller

Ensure order association is set correctly when adding admin adjustments
This commit is contained in:
Matt-Yorkley
2021-03-15 16:51:10 +01:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -2,16 +2,18 @@ module Spree
module Admin
class AdjustmentsController < ::Admin::ResourceController
belongs_to 'spree/order', find_by: :number
destroy.after :reload_order
prepend_before_action :set_included_tax, only: [:create, :update]
before_action :set_order_id, only: [:create, :update]
after_action :update_order, only: [:create, :update, :destroy]
before_action :set_default_tax_rate, only: :edit
before_action :enable_updates, only: :update
private
def reload_order
def update_order
@order.reload
@order.update!
end
def collection
@@ -22,6 +24,10 @@ module Spree
parent.all_adjustments.eligible.find(params[:id])
end
def set_order_id
@adjustment.order_id = parent.id
end
# Choose a default tax rate to show on the edit form. The adjustment stores its included
# tax in dollars, but doesn't store the source of the tax (ie. TaxRate that generated it).
# We guess which tax rate here, choosing:

View File

@@ -21,6 +21,9 @@ module Spree
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(0)
expect(a.order_id).to eq(order.id)
expect(order.reload.total).to eq 110
end
it "calculates included tax when a tax rate is provided" do
@@ -31,6 +34,9 @@ module Spree
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(10)
expect(a.order_id).to eq(order.id)
expect(order.reload.total).to eq 110
end
end
@@ -47,6 +53,9 @@ module Spree
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(0)
expect(a.order_id).to eq(order.id)
expect(order.reload.total).to eq 110
end
it "calculates included tax when a tax rate is provided" do
@@ -57,6 +66,9 @@ module Spree
expect(a.label).to eq('Testing included tax')
expect(a.amount).to eq(110)
expect(a.included_tax).to eq(10)
expect(a.order_id).to eq(order.id)
expect(order.reload.total).to eq 110
end
end
end