From b2bc7956bdf68c431c53ac54ba5256a887baa96e Mon Sep 17 00:00:00 2001
From: Mathieu Walravens <wama@odoo.com>
Date: Fri, 1 Sep 2023 18:01:28 +0200
Subject: [PATCH] [FIX] stock: clean-up sequences at uninstall

When stock is uninstalled, the sequences used in the warehouses for the
picking types are kept. However, since [1], picking types cannot be
duplicated anymore. When the module is re-installed, the picking types
are created with the same name, which is not allowed by [1].

[1]: https://github.com/odoo/odoo/commit/9034602a028fb22fbd139cf41a2f5c71d9d8d032

opw-3484352

closes odoo/odoo#134032

Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
---
 addons/stock/__init__.py     | 5 +++++
 addons/stock/__manifest__.py | 1 +
 2 files changed, 6 insertions(+)

diff --git a/addons/stock/__init__.py b/addons/stock/__init__.py
index 92b1ca625409..39963bcad57a 100644
--- a/addons/stock/__init__.py
+++ b/addons/stock/__init__.py
@@ -29,3 +29,8 @@ def _assign_default_mail_template_picking_id(cr, registry):
         company_ids_without_default_mail_template_id.write({
             'stock_mail_confirmation_template_id': default_mail_template_id.id,
         })
+
+def uninstall_hook(cr, registry):
+    env = api.Environment(cr, SUPERUSER_ID, {})
+    picking_type_ids = env["stock.picking.type"].with_context({"active_test": False}).search([])
+    picking_type_ids.sequence_id.unlink()
diff --git a/addons/stock/__manifest__.py b/addons/stock/__manifest__.py
index dee5b130959c..57238dc634e5 100644
--- a/addons/stock/__manifest__.py
+++ b/addons/stock/__manifest__.py
@@ -93,6 +93,7 @@
     'application': True,
     'pre_init_hook': 'pre_init_hook',
     'post_init_hook': '_assign_default_mail_template_picking_id',
+    'uninstall_hook': 'uninstall_hook',
     'assets': {
         'web.report_assets_common': [
             # legacy reports (delete when all reports are converted)
-- 
GitLab