diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index fbee3631893..4b58ef07e6d 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -566,7 +566,7 @@ class StockMoveLine(models.Model): raise UserError(_('You need to supply a Lot/Serial Number for product: \n - ') + '\n - '.join(mls_tracked_without_lot.mapped('product_id.display_name'))) ml_to_create_lot = self.env['stock.move.line'].browse(ml_ids_to_create_lot) - ml_to_create_lot._create_and_assign_production_lot() + ml_to_create_lot.with_context(do_not_unreserve=True)._create_and_assign_production_lot() mls_to_delete = self.env['stock.move.line'].browse(ml_ids_to_delete) mls_to_delete.unlink() diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index f5286a57f3b..b6c18882045 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -2232,6 +2232,26 @@ class TestSinglePicking(TestStockCommon): self.assertEqual(picking.move_ids.state, 'cancel', "Stock move should be in a cancel state.") self.assertEqual(picking.state, 'cancel', "Picking should be in a cancel state.") + def test_immediate_picking_with_lot(self): + self.productA.tracking = 'serial' + picking = self.env['stock.picking'].create({ + 'location_id': self.supplier_location, + 'location_dest_id': self.stock_location, + 'picking_type_id': self.picking_type_in, + 'immediate_transfer': True, + 'move_line_ids': [(0, 0, { + 'product_id': self.productA.id, + 'product_uom_id': self.productA.uom_id.id, + 'location_id': self.supplier_location, + 'location_dest_id': self.stock_location, + 'qty_done': 1, + 'lot_name': '12345', + })] + }) + + self.assertEqual(len(picking.move_line_ids), 1, "Picking should have a single move line") + picking.button_validate() + self.assertEqual(len(picking.move_line_ids), 1, "Picking should have a single move line") class TestStockUOM(TestStockCommon): @classmethod