From 09f985aba5887f9036ce48109b35aa82f1c81c78 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Thu, 29 Apr 2021 11:44:00 +0000 Subject: [PATCH] [FIX] stock: allow to use already defined SN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Define a [DEMO] prod with tracking by SN and add some SNs - Activate "use existing lot/serial number" on the receipt picking type - Create a purchase order for [DEMO] - Process the receipt in the barcode app: * Scan the product * Scan the SN barcode * Validate User will get an error. It seems that Odoo is trying to create this SN instead of matching the existing one opw-2474347 closes odoo/odoo#73610 X-original-commit: 09a1252b8a5bc194ffccd6c2437985328d08ba08 Related: odoo/enterprise#19632 Signed-off-by: Rémy Voet Signed-off-by: agr-odoo --- addons/stock/models/stock_move_line.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index ab4dba26bc1..a5e87d1fdb9 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -494,17 +494,14 @@ 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: - 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) + 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 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: