mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-22 05:18:51 +00:00
quick fix: update fees after updating order
This commit is contained in:
@@ -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
|
||||
|
||||
30
spec/controllers/spree/admin/orders_controller_spec.rb
Normal file
30
spec/controllers/spree/admin/orders_controller_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user