diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index b44f89fea14..0abf4a21851 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -463,14 +463,17 @@ class StockMoveLine(models.Model): # If a picking type is linked, we may have to create a production lot on # the fly before assigning it to the move line if the user checked both # `use_create_lots` and `use_existing_lots`. - if ml.lot_name and not ml.lot_id: - lot = self.env['stock.production.lot'].search([ - ('company_id', '=', ml.company_id.id), - ('product_id', '=', ml.product_id.id), - ('name', '=', ml.lot_name), - ], limit=1) - if lot: - ml.lot_id = lot.id + if ml.lot_name: + if ml.product_id.tracking == 'lot' and not ml.lot_id: + lot = self.env['stock.production.lot'].search([ + ('company_id', '=', ml.company_id.id), + ('product_id', '=', ml.product_id.id), + ('name', '=', ml.lot_name), + ], limit=1) + if lot: + ml.lot_id = lot.id + else: + ml_ids_to_create_lot.add(ml.id) else: ml_ids_to_create_lot.add(ml.id) elif not picking_type_id.use_create_lots and not picking_type_id.use_existing_lots: