From b578521324ad690784b4d3cddade7aef5e453df6 Mon Sep 17 00:00:00 2001 From: Atul Patel Date: Fri, 20 Oct 2023 08:46:26 +0300 Subject: [PATCH] [FIX] stock: avoid duplicating sequence for new picking type During upgrade, it try to create picking type if not exist like pos type and everytime will create new sequence too for that picking type. during the creation of picking type there is python constraints that raised if same sequence name with same company exist. so to avoid that will check before creating new sequence if already same company sequence exist then update the sequence name with id using copy prefix to easily identify as copy name. closes odoo/odoo#143609 X-original-commit: e16c15b5306f841d8da6ec3e951aff606e377134 Signed-off-by: William Henrotin (whe) --- addons/stock/models/stock_warehouse.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 14f63546bf5..352e6ff1e2d 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -354,6 +354,9 @@ class Warehouse(models.Model): else: data[picking_type].update(create_data[picking_type]) sequence = IrSequenceSudo.create(sequence_data[picking_type]) + existing_sequence = IrSequenceSudo.search_count([('company_id', '=', sequence.company_id.id), ('name', '=', sequence.name)], limit=1) + if existing_sequence: + sequence.name = _("%(name)s (copy)(%(id)s)", name=sequence.name, id=str(sequence.id)) values.update(warehouse_id=self.id, color=color, sequence_id=sequence.id) warehouse_data[picking_type] = PickingType.create(values).id