Compare commits

...

3 Commits

Author SHA1 Message Date
Matt-Yorkley
2e8ebacce3 Add index on spree_adjustments.order_id 2021-03-15 21:25:31 +00:00
Matt-Yorkley
6f35e4e662 Update order total when editing admin adjustments 2021-03-15 11:53:40 +00:00
Matt-Yorkley
2341494555 Ensure order association is set correctly when adding admin adjustments 2021-03-15 11:53:38 +00:00
4 changed files with 27 additions and 3 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

@@ -0,0 +1,5 @@
class AddIndexToAdjustments < ActiveRecord::Migration
def change
add_index :spree_adjustments, :order_id
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20210216203057) do
ActiveRecord::Schema.define(version: 20210312095840) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -399,6 +399,7 @@ ActiveRecord::Schema.define(version: 20210216203057) do
end
add_index "spree_adjustments", ["adjustable_id"], name: "index_adjustments_on_order_id", using: :btree
add_index "spree_adjustments", ["order_id"], name: "index_spree_adjustments_on_order_id", using: :btree
create_table "spree_assets", force: :cascade do |t|
t.integer "viewable_id"

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