From b8cf940247ce746bf2ccdd77cbcb9bfde5c026d2 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 28 Jun 2017 15:36:17 +0200 Subject: [ADD] base: new wizard to uninstall a module (#17284) The "Uninstall" button on the module form no longer changes the state of modules, so that cancelling the wizard will not unexpectedly perform the uninstallation. The uninstallation is performed only by clicking on the "Confirm" button on the wizard. Moreover, the wizard provides clearer information about the impact of the uninstallation: what apps/modules will be uninstalled and what documents (models) will be lost. --- odoo/addons/base/module/wizard/__init__.py | 1 + .../base/module/wizard/base_module_uninstall.py | 55 ++++++++++++++++++++++ .../module/wizard/base_module_uninstall_view.xml | 52 ++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 odoo/addons/base/module/wizard/base_module_uninstall.py create mode 100644 odoo/addons/base/module/wizard/base_module_uninstall_view.xml (limited to 'odoo/addons/base/module/wizard') diff --git a/odoo/addons/base/module/wizard/__init__.py b/odoo/addons/base/module/wizard/__init__.py index 72162359952..ece1521da87 100644 --- a/odoo/addons/base/module/wizard/__init__.py +++ b/odoo/addons/base/module/wizard/__init__.py @@ -5,5 +5,6 @@ from . import base_module_update from . import base_language_install from . import base_import_language from . import base_module_upgrade +from . import base_module_uninstall from . import base_export_language from . import base_update_translations diff --git a/odoo/addons/base/module/wizard/base_module_uninstall.py b/odoo/addons/base/module/wizard/base_module_uninstall.py new file mode 100644 index 00000000000..1168e57341c --- /dev/null +++ b/odoo/addons/base/module/wizard/base_module_uninstall.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class BaseModuleUninstall(models.TransientModel): + _name = "base.module.uninstall" + _description = "Module Uninstallation" + + show_all = fields.Boolean() + module_id = fields.Many2one('ir.module.module', string="Module", required=True, + domain=[('state', 'in', ['installed', 'to upgrade', 'to install'])]) + module_ids = fields.Many2many('ir.module.module', string="Impacted modules", + compute='_compute_module_ids') + model_ids = fields.Many2many('ir.model', string="Impacted data models", + compute='_compute_model_ids') + + def _get_modules(self): + """ Return all the modules impacted by self. """ + return self.module_id.downstream_dependencies(self.module_id) + + @api.depends('module_id', 'show_all') + def _compute_module_ids(self): + for wizard in self: + modules = wizard._get_modules() + wizard.module_ids = modules if wizard.show_all else modules.filtered('application') + + def _get_models(self): + """ Return the models (ir.model) to consider for the impact. """ + return self.env['ir.model'].search([('transient', '=', False)]) + + @api.depends('module_ids') + def _compute_model_ids(self): + ir_models = self._get_models() + ir_models_xids = ir_models._get_external_ids() + for wizard in self: + if wizard.module_id: + module_names = set(wizard._get_modules().mapped('name')) + # find the models that have all their XIDs in the given modules + def lost(model): + return all(xid.split('.')[0] in module_names + for xid in ir_models_xids.get(model.id, ())) + self.model_ids = ir_models.filtered(lost).sorted('name') + + @api.onchange('module_id') + def _onchange_module_id(self): + # if we select a technical module, show technical modules by default + if not self.module_id.application: + self.show_all = True + + @api.multi + def action_uninstall(self): + modules = self.mapped('module_id') + return modules.button_immediate_uninstall() diff --git a/odoo/addons/base/module/wizard/base_module_uninstall_view.xml b/odoo/addons/base/module/wizard/base_module_uninstall_view.xml new file mode 100644 index 00000000000..43da6a2bcde --- /dev/null +++ b/odoo/addons/base/module/wizard/base_module_uninstall_view.xml @@ -0,0 +1,52 @@ + + + + + + Uninstall module + base.module.uninstall + +
+ +

The following apps will be uninstalled

+ Show technical modules + + + + + + + + +
+ +
+

+

+
+ +

+
+
+
+
+
+
+

The following documents will be permanently lost

+ + + + + + + + +
+
+ +
+
-- cgit v1.2.3