diff --git a/base_exception/__init__.py b/base_exception/__init__.py index 3c4dc4909..01e5383e5 100644 --- a/base_exception/__init__.py +++ b/base_exception/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2011 Raphaël Valyi, Renato Lima, Guewen Baconnier, Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import wizard, models +from .hooks import pre_init_hook diff --git a/base_exception/__manifest__.py b/base_exception/__manifest__.py index 6a42b0b1b..422e24dfb 100644 --- a/base_exception/__manifest__.py +++ b/base_exception/__manifest__.py @@ -18,4 +18,5 @@ 'views/base_exception_view.xml', ], 'installable': True, + 'pre_init_hook': 'pre_init_hook', } diff --git a/base_exception/hooks.py b/base_exception/hooks.py new file mode 100644 index 000000000..9a1f8ba38 --- /dev/null +++ b/base_exception/hooks.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Akretion, Mourad EL HADJ MIMOUNE +# Copyright 2018 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +def pre_init_hook(cr): + """If coming from v9 where only `sale_exception` is installed, when + auto-installing this one by dependencies, we should take care of + renaming previous table before the new model is loaded. + """ + cr.execute("SELECT 1 FROM pg_class WHERE relname = 'sale_exception'") + if not cr.fetchone(): + return # fresh install, so exiting + from openupgradelib import openupgrade + openupgrade.rename_tables(cr, [('sale_exception', 'exception_rule')]) + openupgrade.rename_models(cr, [('sale.exception', 'exception.rule')]) diff --git a/base_exception/migrations/10.0.1.0.0/pre-migration.py b/base_exception/migrations/10.0.1.0.0/pre-migration.py deleted file mode 100644 index 35600697f..000000000 --- a/base_exception/migrations/10.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion, Mourad EL HADJ MIMOUNE -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - - -@openupgrade.migrate(use_env=True) -def migrate(env, version): - cr = env.cr - openupgrade.rename_tables(cr, [('sale_exception', 'exception_rule')]) - openupgrade.rename_models(cr, [('sale.exception', 'exception.rule')])