From 8822b7cfa41b65113b2482f8e057ef6c46398f8d Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Mon, 24 Jul 2017 16:06:57 +0200 Subject: [PATCH] [FIX] stock, stock_account: add move when picking is available When a picking is available, any added stock move should directly be in the available state. This is done thanks to a key in context put in the one2many (stock.move) field on the picking view and an override of stock.move's default_get. Sadly, an extension of the picking view in stock_account redefined the context attributes, and the new context did not have the special key we need. As all the context keys present in stock_account are present in stock, we remove the extension. And we add a simple test in stock. --- addons/stock/tests/test_move2.py | 47 ++++++++++++++++++- .../views/stock_account_views.xml | 11 ----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index b33046f4eae..e6773e93fd9 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -23,7 +23,7 @@ class TestPickShip(TestStockCommon): 'location_dest_id': self.customer_location, 'state': 'waiting', }) - + picking_pick = self.env['stock.picking'].create({ 'location_id': self.stock_location, 'location_dest_id': self.pack_location, @@ -701,3 +701,48 @@ class TestSinglePicking(TestStockCommon): self.assertEqual(len(move1.move_line_ids), 2) self.assertEqual(move1.move_line_ids[0].lot_id.id, serial1.id) self.assertEqual(move1.move_line_ids[1].lot_id.id, serial2.id) + + def test_add_move_when_picking_is_available_1(self): + """ Check that any move added in a picking once it's assigned is directly considered as + assigned and bypass the reservation. + """ + delivery_order = self.env['stock.picking'].create({ + 'location_id': self.pack_location, + 'location_dest_id': self.customer_location, + 'partner_id': self.partner_delta_id, + 'picking_type_id': self.picking_type_out, + }) + self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 2, + 'product_uom': self.productA.uom_id.id, + 'picking_id': delivery_order.id, + 'location_id': self.pack_location, + 'location_dest_id': self.customer_location, + }) + + # make some stock + pack_location = self.env['stock.location'].browse(self.pack_location) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 2) + + # assign + delivery_order.action_confirm() + delivery_order.action_assign() + self.assertEqual(delivery_order.state, 'assigned') + + # add a move + move2 = self.MoveObj\ + .with_context(default_picking_id=delivery_order.id)\ + .create({ + 'name': self.productA.name, + 'product_id': self.productB.id, + 'product_uom_qty': 1, + 'product_uom': self.productA.uom_id.id, + 'picking_id': delivery_order.id, + 'location_id': self.pack_location, + 'location_dest_id': self.customer_location, + }) + + self.assertEqual(move2.state, 'assigned') + self.assertEqual(delivery_order.state, 'assigned') diff --git a/addons/stock_account/views/stock_account_views.xml b/addons/stock_account/views/stock_account_views.xml index e6e570a8184..fa14fc21e6b 100644 --- a/addons/stock_account/views/stock_account_views.xml +++ b/addons/stock_account/views/stock_account_views.xml @@ -27,17 +27,6 @@ - - stock.picking.form.inherit - stock.picking - - - - {'address_in_id': partner_id, 'form_view_ref':'stock.view_move_picking_form', 'tree_view_ref':'stock.view_move_picking_tree', 'default_picking_type_id': picking_type_id, 'default_location_id': location_id, 'default_location_dest_id': location_dest_id} - - - - stock.return.picking.stock.account.form