From 30db4cdd7511490d183fa084d5fff7bd9f34363a Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 26 Feb 2018 15:12:25 +0100 Subject: [PATCH] [FIX] stock: remove existing demo data on reinstall Previous to this rev.: *Install stock w/ demo data *Uninstall stock *Reinstall stock Result: Boom! Installation crashes. Reason: The demo data installed with stock is not properly deleted after the module is uninstalled, which causes issues/conflicts upon reinstallation of the same demo data. Solution: Remove any demo data of stock models upon installation if any exist through a pre_init_hook, ideally this would be done by overriding the unlink() of the affected models / setting some ondelete='cascade', or even a uninstall_hook, however these solutions prove insufficient for databases that are currently affected by the problem. Fixes #22243 --- addons/stock/__init__.py | 14 +++++++++++++- addons/stock/__manifest__.py | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/stock/__init__.py b/addons/stock/__init__.py index ddac13e1a0e..bb5953c4834 100644 --- a/addons/stock/__init__.py +++ b/addons/stock/__init__.py @@ -4,4 +4,16 @@ import controllers import models import report -import wizard \ No newline at end of file +import wizard + + +from odoo import api, SUPERUSER_ID + + +# TODO: Apply proper fix & remove in master +def pre_init_hook(cr): + env = api.Environment(cr, SUPERUSER_ID, {}) + env['ir.model.data'].search([ + ('model', 'like', '%stock%'), + ('module', '=', 'stock') + ]).unlink() diff --git a/addons/stock/__manifest__.py b/addons/stock/__manifest__.py index 9729e82be32..8f9a088fbf9 100644 --- a/addons/stock/__manifest__.py +++ b/addons/stock/__manifest__.py @@ -101,4 +101,5 @@ Dashboard / Reports for Inventory Management will include: 'installable': True, 'application': True, 'auto_install': False, + 'pre_init_hook': 'pre_init_hook', }