mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Merge pull request #12229 from cyrillefr/Decreasing-the-quantity-of-an-item-does-not-update-enterprise-fees-per-item
[BO Orders] Update Entreprise fees when decreasing quantity
This commit is contained in:
@@ -85,6 +85,8 @@ module Api
|
||||
@order.contents.remove(variant, quantity, @shipment, restock_item)
|
||||
@shipment.reload if @shipment.persisted?
|
||||
|
||||
@order.recreate_all_fees!
|
||||
|
||||
render json: @shipment, serializer: Api::ShipmentSerializer, status: :ok
|
||||
end
|
||||
|
||||
|
||||
@@ -367,13 +367,17 @@ describe Api::V0::ShipmentsController, type: :controller do
|
||||
instance_double(Spree::Order, number: "123", distributor: variant.product.supplier)
|
||||
}
|
||||
let(:contents) { instance_double(Spree::OrderContents) }
|
||||
let(:fee_order_shipment) {
|
||||
instance_double(Spree::Shipment)
|
||||
}
|
||||
|
||||
before do
|
||||
allow(Spree::Order).to receive(:find_by!) { fee_order }
|
||||
allow(controller).to receive(:find_and_update_shipment) {}
|
||||
allow(controller).to receive(:refuse_changing_cancelled_orders) {}
|
||||
allow(fee_order).to receive(:contents) { contents }
|
||||
allow(contents).to receive(:add) {}
|
||||
allow(contents).to receive_messages(add: {}, remove: {})
|
||||
allow(fee_order).to receive_message_chain(:shipments, :find_by!) { fee_order_shipment }
|
||||
allow(fee_order_shipment).to receive_messages(update: nil, reload: nil, persisted?: nil)
|
||||
allow(fee_order).to receive(:recreate_all_fees!)
|
||||
end
|
||||
|
||||
@@ -382,6 +386,12 @@ describe Api::V0::ShipmentsController, type: :controller do
|
||||
spree_put :add, params
|
||||
expect(fee_order).to have_received(:recreate_all_fees!)
|
||||
end
|
||||
|
||||
it "recalculates fees for the line item when qty is decreased" do
|
||||
params[:order_id] = fee_order.number
|
||||
spree_put :remove, params
|
||||
expect(fee_order).to have_received(:recreate_all_fees!)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user