diff --git a/stock_picking_force_assign/__manifest__.py b/stock_picking_force_assign/__manifest__.py index e4df74ad3e9c..2acc6f12ac26 100644 --- a/stock_picking_force_assign/__manifest__.py +++ b/stock_picking_force_assign/__manifest__.py @@ -11,6 +11,7 @@ "license": "AGPL-3", "depends": [ "stock", + "purchase", ], "data": [ "security/stock_picking_force_assign_security.xml", diff --git a/stock_picking_force_assign/models/stock_picking.py b/stock_picking_force_assign/models/stock_picking.py index e3c931715443..ba9431280098 100644 --- a/stock_picking_force_assign/models/stock_picking.py +++ b/stock_picking_force_assign/models/stock_picking.py @@ -47,6 +47,7 @@ def _force_assign_find_moves(self): precision_digits=result._fields['product_qty'].digits, ) + stock_available = False for move in self.mapped('move_lines'): if move.state == 'cancel': continue @@ -55,6 +56,7 @@ def _force_assign_find_moves(self): move.availability ) if float_compare(demand, 0) <= 0: + stock_available = True continue candidates = self.env['stock.move'].search([ ('id', 'not in', result.ids), @@ -63,6 +65,8 @@ def _force_assign_find_moves(self): ('product_id', '=', move.product_id.id), ('state', 'in', ('partially_available', 'assigned')), ], order='write_date asc') + if candidates and not stock_available: + stock_available = True for candidate in candidates: if float_compare(demand, 0) > 0: @@ -78,6 +82,10 @@ def _force_assign_find_moves(self): move.product_id.name, demand ) ) + if not stock_available: + raise exceptions.UserError(_( + 'There is no sufficient stock in this location to reserve ' + 'stock for this order.')) return result def _unchain_waiting(self, link_template): diff --git a/stock_picking_force_assign/tests/test_stock_picking_force_assign.py b/stock_picking_force_assign/tests/test_stock_picking_force_assign.py index ce5357a4596e..a44421ab2d69 100644 --- a/stock_picking_force_assign/tests/test_stock_picking_force_assign.py +++ b/stock_picking_force_assign/tests/test_stock_picking_force_assign.py @@ -8,20 +8,18 @@ class TestStockPickingForceAssign(TransactionCase): def setUp(self, *args, **kwargs): super().setUp(*args, **kwargs) + self.location = self.env.ref('stock.stock_location_stock') route_buy = self.env['stock.location.route'].create({ 'name': 'Buy', 'rule_ids': [(0, 0, { 'name': 'Buy', - 'action': 'buy', + 'action': 'pull', 'picking_type_id': self.env.ref('stock.picking_type_in').id, - 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_id': self.location.id, })] }) route_mto = self.env.ref('stock.route_warehouse0_mto') - self.product = self.env['product.product'].create({ - 'name': 'stockable', - 'type': 'product', - }) + self.product = self.product = self.env.ref('product.product_delivery_01') self.product2 = self.product.copy({ 'name': 'stockable-mto', 'purchase_ok': True, @@ -37,7 +35,7 @@ def setUp(self, *args, **kwargs): self.assigned_picking = self.env['stock.picking'].create({ 'name': 'Picking to unassign', 'picking_type_id': self.env.ref('stock.picking_type_out').id, - 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_id': self.location.id, 'location_dest_id': self.env.ref('stock.stock_location_customers').id, 'move_lines': [(0, 0, { @@ -90,11 +88,14 @@ def test_happy_flow(self): def test_on_done_picking(self): """ Test force assigning a done picking """ + self.env['ir.config_parameter'].set_param( + 'stock_picking_force_assign.allow_partial', True) self.waiting_picking.action_assign() self.assigned_picking.move_line_ids.qty_done = 42 self.assigned_picking.action_done() self.assertEqual(self.assigned_picking.state, 'done') - with self.assertRaises(UserError): + with self.assertRaisesRegex( + UserError, 'There is no sufficient stock in this location'): self.waiting_picking.action_force_assign_pickings() def test_partial(self): diff --git a/stock_split_picking/views/stock_partial_picking.xml b/stock_split_picking/views/stock_partial_picking.xml index f06e2e6ab498..d2a834f1574d 100644 --- a/stock_split_picking/views/stock_partial_picking.xml +++ b/stock_split_picking/views/stock_partial_picking.xml @@ -8,7 +8,7 @@