From 36b7d980ca117595fbeae29107bcca3ec5c35fcf Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 21 Feb 2017 17:25:44 +0100 Subject: [PATCH] [FIX] sale_margin: uninstall_hook When uninstalling the module sale_margin, the view 'sale_report' was deleted because this view was overwritten in this module. But the module sale still uses the 'sale_report' view so it raised an error each time this view was required. opw:709328 --- addons/sale_margin/__init__.py | 17 +++++++++++++++++ addons/sale_margin/__openerp__.py | 1 + 2 files changed, 18 insertions(+) diff --git a/addons/sale_margin/__init__.py b/addons/sale_margin/__init__.py index c61d2d59a98..59c0d9d02a1 100644 --- a/addons/sale_margin/__init__.py +++ b/addons/sale_margin/__init__.py @@ -1,4 +1,21 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +from functools import partial +import openerp +from openerp import api, SUPERUSER_ID import sale_margin import report + + + +def uninstall_hook(cr, registry): + def recreate_view(dbname): + db_registry = openerp.modules.registry.RegistryManager.new(dbname) + with api.Environment.manage(), db_registry.cursor() as cr: + env = api.Environment(cr, SUPERUSER_ID, {}) + if 'sale.report' in env: + env['ir.module.module'].search([('name', '=', 'sale_margin')]).state + env['sale.report'].init() + + + cr.after("commit", partial(recreate_view, cr.dbname)) \ No newline at end of file diff --git a/addons/sale_margin/__openerp__.py b/addons/sale_margin/__openerp__.py index 076cf100064..f993d62cb57 100644 --- a/addons/sale_margin/__openerp__.py +++ b/addons/sale_margin/__openerp__.py @@ -18,4 +18,5 @@ Price and Cost Price. 'data':['security/ir.model.access.csv','sale_margin_view.xml'], 'auto_install': False, 'installable': True, + 'uninstall_hook': "uninstall_hook", }