quick fix: update fees after updating order

This commit is contained in:
Maikel Linke
2015-04-30 16:29:51 +10:00
parent ecf635e080
commit 5efc0a5110
2 changed files with 41 additions and 0 deletions

View File

@@ -9,6 +9,13 @@ Spree::Admin::OrdersController.class_eval do
# in an auth failure as the @order object is nil for collection actions
before_filter :check_authorization, :except => :bulk_management
# After updating an order, the fees should be updated as well
# Currently, adding or deleting line items does not trigger updating the
# fees! This is a quick fix for that.
# TODO: update fees when adding/removing line items
# instead of the update_distribution_charge method.
after_filter :update_distribution_charge, :only => :update
respond_override :index => { :html =>
{ :success => lambda {
# Filter orders to only show those distributed by current user (or all for admin user)
@@ -26,4 +33,8 @@ Spree::Admin::OrdersController.class_eval do
respond_with(@order) { |format| format.html { redirect_to :back } }
end
def update_distribution_charge
@order.update_distribution_charge!
end
end

View File

@@ -0,0 +1,30 @@
require 'spec_helper'
describe Spree::Admin::OrdersController do
let!(:order) { create(:order) }
context "updating an order with line items" do
let(:line_item) { create(:line_item) }
before { login_as_admin }
it "updates distribution charges" do
order.line_items << line_item
order.save
Spree::Order.any_instance.should_receive(:update_distribution_charge!)
spree_put :update, {
id: order,
order: {
number: order.number,
distributor_id: order.distributor_id,
order_cycle_id: order.order_cycle_id,
line_items_attributes: [
{
id: line_item.id,
quantity: line_item.quantity
}
]
}
}
end
end
end