[FIX] stock: allow to use already defined SN

- 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 <ryv-odoo@users.noreply.github.com>
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2021-07-20 08:48:24 +00:00
parent 2c028ca2a6
commit 09f985aba5
+8 -11
View File
@@ -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: