From c9c5f4b7859cb414d37d99f25297f4175c7df74f Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 24 Jan 2013 19:28:08 +0100 Subject: [PATCH 1/3] [FIX] res.config.installer: correct module installing bzr revid: chs@openerp.com-20130124182808-5xvdc0mqst0h2970 --- openerp/addons/base/res/res_config.py | 90 ++++++++++++++++----------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/openerp/addons/base/res/res_config.py b/openerp/addons/base/res/res_config.py index a2368a9f508..4c59180acc3 100644 --- a/openerp/addons/base/res/res_config.py +++ b/openerp/addons/base/res/res_config.py @@ -21,14 +21,47 @@ import logging from operator import attrgetter -import openerp -from openerp import pooler from openerp.osv import osv, fields from openerp.tools import ustr from openerp.tools.translate import _ _logger = logging.getLogger(__name__) + +class res_config_module_installation_mixin(object): + def _install_modules(self, cr, uid, modules, context): + """Install the requested modules. + return the next action to execute + + modules is a list of tuples + (mod_name, browse_record | None) + """ + ir_module = self.pool.get('ir.module.module') + to_install_ids = [] + to_install_missing_names = [] + + for name, module in modules: + if not module: + to_install_missing_names.append(name) + elif module.state == 'uninstalled': + to_install_ids.append(module.id) + + if to_install_ids: + ir_module.button_immediate_install(cr, uid, to_install_ids, context=context) + + if to_install_missing_names: + return { + 'type': 'ir.actions.client', + 'tag': 'apps', + 'params': {'modules': to_install_missing_names}, + } + + config = self.pool.get('res.config').next(cr, uid, [], context=context) or {} + if config.get('type') not in ('ir.actions.act_window_close',): + return config + + return None + class res_config_configurable(osv.osv_memory): ''' Base classes for new-style configuration items @@ -153,7 +186,7 @@ class res_config_configurable(osv.osv_memory): res_config_configurable() -class res_config_installer(osv.osv_memory): +class res_config_installer(osv.osv_memory, res_config_module_installation_mixin): """ New-style configuration base specialized for addons selection and installation. @@ -351,17 +384,18 @@ class res_config_installer(osv.osv_memory): return fields def execute(self, cr, uid, ids, context=None): - modules = self.pool.get('ir.module.module') to_install = list(self.modules_to_install( cr, uid, ids, context=context)) _logger.info('Selecting addons %s to install', to_install) - modules.state_update( - cr, uid, - modules.search(cr, uid, [('name','in',to_install)]), - 'to install', ['uninstalled'], context=context) - cr.commit() - openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname) - new_db, self.pool = pooler.restart_pool(cr.dbname, update_module=True) + + ir_module = self.pool.get('ir.module.module') + modules = [] + for name in to_install: + mod_ids = ir_module.search(cr, uid, [('name', '=', name)]) + record = ir_module.browse(cr, uid, mod_ids[0], context) if mod_ids else None + modules.append((name, record)) + + return self._install_modules(cr, uid, modules, context=context) res_config_installer() @@ -402,8 +436,7 @@ class ir_actions_configuration_wizard(osv.osv_memory): ir_actions_configuration_wizard() - -class res_config_settings(osv.osv_memory): +class res_config_settings(osv.osv_memory, res_config_module_installation_mixin): """ Base configuration wizard for application settings. It provides support for setting default values, assigning groups to employee users, and installing modules. To make such a 'settings' wizard, define a model like:: @@ -527,37 +560,22 @@ class res_config_settings(osv.osv_memory): getattr(self, method)(cr, uid, ids, context) # module fields: install/uninstall the selected modules - to_install_missing_names = [] + to_install = [] to_uninstall_ids = [] - to_install_ids = [] lm = len('module_') for name, module in classified['module']: if config[name]: - if not module: - # missing module, will be provided by apps.openerp.com - to_install_missing_names.append(name[lm:]) - elif module.state == 'uninstalled': - # local module, to be installed - to_install_ids.append(module.id) + to_install.append((name[lm:], module)) else: if module and module.state in ('installed', 'to upgrade'): to_uninstall_ids.append(module.id) if to_uninstall_ids: ir_module.button_immediate_uninstall(cr, uid, to_uninstall_ids, context=context) - if to_install_ids: - ir_module.button_immediate_install(cr, uid, to_install_ids, context=context) - if to_install_missing_names: - return { - 'type': 'ir.actions.client', - 'tag': 'apps', - 'params': {'modules': to_install_missing_names}, - } - - config = self.pool.get('res.config').next(cr, uid, [], context=context) or {} - if config.get('type') not in ('ir.actions.act_window_close',): - return config + action = self._install_modules(cr, uid, to_install, context=context) + if action: + return action # force client-side reload (update user menu and current view) return { @@ -572,17 +590,17 @@ class res_config_settings(osv.osv_memory): if action_ids: return act_window.read(cr, uid, action_ids[0], [], context=context) return {} - + def name_get(self, cr, uid, ids, context=None): """ Override name_get method to return an appropriate configuration wizard name, and not the generated name.""" - + if not ids: return [] # name_get may receive int id instead of an id list if isinstance(ids, (int, long)): ids = [ids] - + act_window = self.pool.get('ir.actions.act_window') action_ids = act_window.search(cr, uid, [('res_model', '=', self._name)], context=context) name = self._name From 16289266c99096a1770fd6039539da26a0ce7c0f Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 25 Jan 2013 14:34:53 +0100 Subject: [PATCH 2/3] [FIX] res.config.installer: correct module installing bzr revid: chs@openerp.com-20130125133453-aqu5eotetdyb2zpj --- openerp/addons/base/res/res_config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/res/res_config.py b/openerp/addons/base/res/res_config.py index 4c59180acc3..1ca6fd57cfa 100644 --- a/openerp/addons/base/res/res_config.py +++ b/openerp/addons/base/res/res_config.py @@ -56,10 +56,6 @@ class res_config_module_installation_mixin(object): 'params': {'modules': to_install_missing_names}, } - config = self.pool.get('res.config').next(cr, uid, [], context=context) or {} - if config.get('type') not in ('ir.actions.act_window_close',): - return config - return None class res_config_configurable(osv.osv_memory): @@ -577,6 +573,10 @@ class res_config_settings(osv.osv_memory, res_config_module_installation_mixin): if action: return action + config = self.pool.get('res.config').next(cr, uid, [], context=context) or {} + if config.get('type') not in ('ir.actions.act_window_close',): + return config + # force client-side reload (update user menu and current view) return { 'type': 'ir.actions.client', From b01528e3f089b3c98a00f0157a015382874c3d30 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 11 Apr 2013 20:36:34 +0200 Subject: [PATCH 3/3] [FIX] res_config: add missing import lost during previous commit bzr revid: chs@openerp.com-20130411183634-pmg5cn82f8s174y1 --- openerp/addons/base/res/res_config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openerp/addons/base/res/res_config.py b/openerp/addons/base/res/res_config.py index 3fe2525ae8d..655173a27a2 100644 --- a/openerp/addons/base/res/res_config.py +++ b/openerp/addons/base/res/res_config.py @@ -21,6 +21,7 @@ import logging from operator import attrgetter +import openerp from openerp.osv import osv, fields from openerp.tools import ustr from openerp.tools.translate import _