From b8cf940247ce746bf2ccdd77cbcb9bfde5c026d2 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 28 Jun 2017 15:36:17 +0200 Subject: [PATCH] [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. --- addons/mail/wizard/__init__.py | 1 + addons/mail/wizard/base_module_uninstall.py | 13 +++++ odoo/addons/base/__manifest__.py | 1 + odoo/addons/base/ir/ir_model.py | 11 ++++ odoo/addons/base/module/module.py | 12 ++++ odoo/addons/base/module/module_view.xml | 2 +- odoo/addons/base/module/wizard/__init__.py | 1 + .../module/wizard/base_module_uninstall.py | 55 +++++++++++++++++++ .../wizard/base_module_uninstall_view.xml | 52 ++++++++++++++++++ 9 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 addons/mail/wizard/base_module_uninstall.py 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 diff --git a/addons/mail/wizard/__init__.py b/addons/mail/wizard/__init__.py index 2181ffa8266..2523a3593b0 100644 --- a/addons/mail/wizard/__init__.py +++ b/addons/mail/wizard/__init__.py @@ -4,3 +4,4 @@ from . import invite from . import mail_compose_message from . import email_template_preview +from . import base_module_uninstall diff --git a/addons/mail/wizard/base_module_uninstall.py b/addons/mail/wizard/base_module_uninstall.py new file mode 100644 index 00000000000..43e029ba851 --- /dev/null +++ b/addons/mail/wizard/base_module_uninstall.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class BaseModuleUninstall(models.TransientModel): + _inherit = "base.module.uninstall" + + def _get_models(self): + # consider mail-thread models only + models = super(BaseModuleUninstall, self)._get_models() + return models.filtered('is_mail_thread') diff --git a/odoo/addons/base/__manifest__.py b/odoo/addons/base/__manifest__.py index 8f8f585473c..be3a4b6af25 100644 --- a/odoo/addons/base/__manifest__.py +++ b/odoo/addons/base/__manifest__.py @@ -46,6 +46,7 @@ The kernel of Odoo, needed for all installation. 'module/wizard/base_language_install_view.xml', 'module/wizard/base_import_language_view.xml', 'module/wizard/base_module_upgrade_view.xml', + 'module/wizard/base_module_uninstall_view.xml', 'module/wizard/base_export_language_view.xml', 'module/wizard/base_update_translations_view.xml', 'module/wizard/base_module_immediate_install.xml', diff --git a/odoo/addons/base/ir/ir_model.py b/odoo/addons/base/ir/ir_model.py index 4ce65a210c2..31828750dfe 100644 --- a/odoo/addons/base/ir/ir_model.py +++ b/odoo/addons/base/ir/ir_model.py @@ -97,6 +97,8 @@ class IrModel(models.Model): transient = fields.Boolean(string="Transient Model") modules = fields.Char(compute='_in_modules', string='In Apps', help='List of modules in which the object is defined or inherited') view_ids = fields.One2many('ir.ui.view', compute='_view_ids', string='Views') + count = fields.Integer(compute='_compute_count', string="Count (incl. archived)", + help="Total number of records in this model") @api.depends() def _inherited_models(self): @@ -119,6 +121,15 @@ class IrModel(models.Model): for model in self: model.view_ids = self.env['ir.ui.view'].search([('model', '=', model.model)]) + @api.depends() + def _compute_count(self): + cr = self.env.cr + for model in self: + records = self.env[model.model] + if not records._abstract: + cr.execute('SELECT COUNT(*) FROM "%s"' % records._table) + model.count = cr.fetchone()[0] + @api.constrains('model') def _check_model_name(self): for model in self: diff --git a/odoo/addons/base/module/module.py b/odoo/addons/base/module/module.py index bfc018f247f..3ded39fb128 100644 --- a/odoo/addons/base/module/module.py +++ b/odoo/addons/base/module/module.py @@ -534,6 +534,18 @@ class Module(models.Model): (self + deps).write({'state': 'to remove'}) return dict(ACTION_DICT, name=_('Uninstall')) + @api.multi + def button_uninstall_wizard(self): + """ Launch the wizard to uninstall the given module. """ + return { + 'type': 'ir.actions.act_window', + 'target': 'new', + 'name': _('Uninstall module'), + 'view_mode': 'form', + 'res_model': 'base.module.uninstall', + 'context': {'default_module_id': self.id}, + } + @api.multi def button_uninstall_cancel(self): self.write({'state': 'installed'}) diff --git a/odoo/addons/base/module/module_view.xml b/odoo/addons/base/module/module_view.xml index 338cb723980..d0e842b5e3e 100644 --- a/odoo/addons/base/module/module_view.xml +++ b/odoo/addons/base/module/module_view.xml @@ -82,7 +82,7 @@