diff --git a/addons/stock/__init__.py b/addons/stock/__init__.py index f912d4ed8fa..9d7a09cb88c 100644 --- a/addons/stock/__init__.py +++ b/addons/stock/__init__.py @@ -28,3 +28,12 @@ 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, {}) + default = env['product.template']._fields['type'].default(env['product.template']) + # stock introduces an option on the `type` Selection field of `product.template` + # if this module is uninstalled and any `product.template` record still points to this option + # the registry will find itself in an unstable state and will most likely crash (eventually) + cr.execute("UPDATE product_template SET type = %s WHERE type = %s", (default, 'product')) diff --git a/addons/stock/__manifest__.py b/addons/stock/__manifest__.py index 8991029f641..e7e101783c0 100644 --- a/addons/stock/__manifest__.py +++ b/addons/stock/__manifest__.py @@ -88,4 +88,5 @@ 'auto_install': False, 'pre_init_hook': 'pre_init_hook', 'post_init_hook': '_assign_default_mail_template_picking_id', + 'uninstall_hook': 'uninstall_hook', }