From 86c24265551920dd837703a7f058970676e62c24 Mon Sep 17 00:00:00 2001 From: Ruchir Shukla <ruchir@bizzappdev.com> Date: Fri, 20 Jun 2014 17:36:26 +0200 Subject: [PATCH] [IMP] module: warning when uninstalling modules When a module is uninstalled, this will also uninstall modules depending of it. To avoid unexpected loss of data, this patch list the modules that will get impacted during the installation. This also affects the configuration pages with on change warnings. --- openerp/addons/base/module/module.py | 1 + openerp/addons/base/module/module_view.xml | 3 +- .../base/module/wizard/base_module_upgrade.py | 14 +++++++ .../wizard/base_module_upgrade_view.xml | 9 +++-- openerp/addons/base/res/res_config.py | 38 +++++++++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/module/module.py b/openerp/addons/base/module/module.py index 6d64abc455b0..89285bdbf4fc 100644 --- a/openerp/addons/base/module/module.py +++ b/openerp/addons/base/module/module.py @@ -485,6 +485,7 @@ class module(osv.osv): 'params': {'menu_id': menu_ids and menu_ids[0] or False} } + #TODO remove me in master, not called anymore def button_immediate_uninstall(self, cr, uid, ids, context=None): """ Uninstall the selected module(s) immediately and fully, diff --git a/openerp/addons/base/module/module_view.xml b/openerp/addons/base/module/module_view.xml index 3923c9de3bd6..fb4295cda682 100644 --- a/openerp/addons/base/module/module_view.xml +++ b/openerp/addons/base/module/module_view.xml @@ -78,8 +78,7 @@ <h2 class="oe_fade"><field name="summary"/></h2> <button name="button_immediate_install" states="uninstalled" string="Install" type="object" class="oe_highlight"/> <button name="button_immediate_upgrade" states="installed" string="Upgrade" type="object" class="oe_highlight"/> - <button name="button_immediate_uninstall" states="installed" string="Uninstall" type="object" - confirm="Do you confirm the uninstallation of this module? This will permanently erase all data currently stored by the module!"/> + <button name="button_uninstall" states="installed" string="Uninstall" type="object"/> <button name="button_uninstall_cancel" states="to remove" string="Cancel Uninstall" type="object"/> <button name="button_upgrade_cancel" states="to upgrade" string="Cancel Upgrade" type="object"/> <button name="button_install_cancel" states="to install" string="Cancel Install" type="object"/> diff --git a/openerp/addons/base/module/wizard/base_module_upgrade.py b/openerp/addons/base/module/wizard/base_module_upgrade.py index b947ba5371f3..559931fddc18 100644 --- a/openerp/addons/base/module/wizard/base_module_upgrade.py +++ b/openerp/addons/base/module/wizard/base_module_upgrade.py @@ -68,6 +68,20 @@ class base_module_upgrade(osv.osv_memory): res = mod_obj.read(cr, uid, ids, ['name','state'], context) return {'module_info': '\n'.join(map(lambda x: x['name']+' : '+x['state'], res))} + def upgrade_module_cancel(self, cr, uid, ids, context=None): + mod_obj = self.pool.get('ir.module.module') + to_installed_ids = mod_obj.search(cr, uid, [ + ('state', 'in', ['to upgrade', 'to remove'])]) + if to_installed_ids: + mod_obj.write(cr, uid, to_installed_ids, {'state': 'installed'}, context=context) + + to_uninstalled_ids = mod_obj.search(cr, uid, [ + ('state', '=', 'to install')]) + if to_uninstalled_ids: + mod_obj.write(cr, uid, to_uninstalled_ids, {'state': 'uninstalled'}, context=context) + + return {'type': 'ir.actions.act_window_close'} + def upgrade_module(self, cr, uid, ids, context=None): ir_module = self.pool.get('ir.module.module') diff --git a/openerp/addons/base/module/wizard/base_module_upgrade_view.xml b/openerp/addons/base/module/wizard/base_module_upgrade_view.xml index 1a1225befcb7..10c023e51482 100644 --- a/openerp/addons/base/module/wizard/base_module_upgrade_view.xml +++ b/openerp/addons/base/module/wizard/base_module_upgrade_view.xml @@ -7,14 +7,15 @@ <field name="model">base.module.upgrade</field> <field name="arch" type="xml"> <form string="System Update" version="7.0"> - <div><label string="Your system will be updated."/></div> - <div><label string="Note that this operation might take a few minutes."/></div> - <separator string="Modules to Update"/> + <p>This module will trigger the uninstallation of below modules.</p> + <p><strong>This operation will permanently erase all data currently stored by the modules!</strong></p> + <p>If you wish to cancel the process, press the cancel button below</p> + <separator string="Impacted Modules"/> <field name="module_info"/> <footer> <button name="upgrade_module" string="Update" type="object" class="oe_highlight"/> or - <button string="Cancel" class="oe_link" special="cancel"/> + <button string="Cancel" class="oe_link" name="upgrade_module_cancel" type="object"/> </footer> </form> </field> diff --git a/openerp/addons/base/res/res_config.py b/openerp/addons/base/res/res_config.py index 1fa5b7bfe494..42ef4ff4b1f6 100644 --- a/openerp/addons/base/res/res_config.py +++ b/openerp/addons/base/res/res_config.py @@ -26,6 +26,7 @@ from openerp import SUPERUSER_ID from openerp.osv import osv, fields from openerp.tools import ustr from openerp.tools.translate import _ +from lxml import etree _logger = logging.getLogger(__name__) @@ -472,6 +473,43 @@ class res_config_settings(osv.osv_memory, res_config_module_installation_mixin): def copy(self, cr, uid, id, values, context=None): raise osv.except_osv(_("Cannot duplicate configuration!"), "") + def fields_view_get(self, cr, user, view_id=None, view_type='form', + context=None, toolbar=False, submenu=False): + ret_val = super(res_config_settings, self).fields_view_get( + cr, user, view_id=view_id, view_type=view_type, context=context, + toolbar=toolbar, submenu=submenu) + + doc = etree.XML(ret_val['arch']) + + for field in ret_val['fields']: + if not field.startswith("module_"): + continue + for node in doc.xpath("//field[@name='%s']" % field): + if 'on_change' not in node.attrib: + node.set("on_change", + "onchange_module(%s, '%s')" % (field, field)) + + ret_val['arch'] = etree.tostring(doc) + return ret_val + + def onchange_module(self, cr, uid, ids, field_value, module_name, context={}): + module_pool = self.pool.get('ir.module.module') + module_ids = module_pool.search( + cr, uid, [('name', '=', module_name.replace("module_", '')), + ('state','in', ['to install', 'installed', 'to upgrade'])], + context=context) + + if module_ids and not field_value: + dep_ids = module_pool.downstream_dependencies(cr, uid, module_ids, context=context) + dep_name = [x.shortdesc for x in module_pool.browse( + cr, uid, dep_ids + module_ids, context=context)] + message = '\n'.join(dep_name) + return {'warning': {'title': _('Warning!'), + 'message': + _('Disabling this option will also uninstall the following modules \n%s' % message) + }} + return {} + def _get_classified_fields(self, cr, uid, context=None): """ return a dictionary with the fields classified by category:: -- GitLab