~openerp-dev/openobject-server/trunk-base-model-thu

« back to all changes in this revision

Viewing changes to openerp/addons/base/res/res_config.py

  • Committer: Vo Minh Thu
  • Date: 2013-05-08 09:34:27 UTC
  • mfrom: (4854.2.18 trunk)
  • Revision ID: vmt@openerp.com-20130508093427-2hr41kztzlsv14u8
[MERGE] merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
_logger = logging.getLogger(__name__)
33
33
 
 
34
 
 
35
class res_config_module_installation_mixin(object):
 
36
    def _install_modules(self, cr, uid, modules, context):
 
37
        """Install the requested modules.
 
38
            return the next action to execute
 
39
 
 
40
          modules is a list of tuples
 
41
            (mod_name, browse_record | None)
 
42
        """
 
43
        ir_module = self.pool.get('ir.module.module')
 
44
        to_install_ids = []
 
45
        to_install_missing_names = []
 
46
 
 
47
        for name, module in modules:
 
48
            if not module:
 
49
                to_install_missing_names.append(name)
 
50
            elif module.state == 'uninstalled':
 
51
                to_install_ids.append(module.id)
 
52
 
 
53
        if to_install_ids:
 
54
            ir_module.button_immediate_install(cr, uid, to_install_ids, context=context)
 
55
 
 
56
        if to_install_missing_names:
 
57
            return {
 
58
                'type': 'ir.actions.client',
 
59
                'tag': 'apps',
 
60
                'params': {'modules': to_install_missing_names},
 
61
            }
 
62
 
 
63
        return None
 
64
 
34
65
class res_config_configurable(osv.osv_memory):
35
66
    ''' Base classes for new-style configuration items
36
67
 
155
186
 
156
187
res_config_configurable()
157
188
 
158
 
class res_config_installer(osv.osv_memory):
 
189
class res_config_installer(osv.osv_memory, res_config_module_installation_mixin):
159
190
    """ New-style configuration base specialized for addons selection
160
191
    and installation.
161
192
 
353
384
        return fields
354
385
 
355
386
    def execute(self, cr, uid, ids, context=None):
356
 
        modules = self.pool['ir.module.module']
357
387
        to_install = list(self.modules_to_install(
358
388
            cr, uid, ids, context=context))
359
389
        _logger.info('Selecting addons %s to install', to_install)
360
 
        modules.state_update(
361
 
            cr, uid,
362
 
            modules.search(cr, uid, [('name','in',to_install)]),
363
 
            'to install', ['uninstalled'], context=context)
364
 
        cr.commit()
365
 
        openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname)
366
 
        openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
 
390
 
 
391
        ir_module = self.pool.get('ir.module.module')
 
392
        modules = []
 
393
        for name in to_install:
 
394
            mod_ids = ir_module.search(cr, uid, [('name', '=', name)])
 
395
            record = ir_module.browse(cr, uid, mod_ids[0], context) if mod_ids else None
 
396
            modules.append((name, record))
 
397
 
 
398
        return self._install_modules(cr, uid, modules, context=context)
367
399
 
368
400
res_config_installer()
369
401
 
404
436
ir_actions_configuration_wizard()
405
437
 
406
438
 
407
 
 
408
 
class res_config_settings(osv.osv_memory):
 
439
class res_config_settings(osv.osv_memory, res_config_module_installation_mixin):
409
440
    """ Base configuration wizard for application settings.  It provides support for setting
410
441
        default values, assigning groups to employee users, and installing modules.
411
442
        To make such a 'settings' wizard, define a model like::
529
560
                getattr(self, method)(cr, uid, ids, context)
530
561
 
531
562
        # module fields: install/uninstall the selected modules
532
 
        to_install_missing_names = []
 
563
        to_install = []
533
564
        to_uninstall_ids = []
534
 
        to_install_ids = []
535
565
        lm = len('module_')
536
566
        for name, module in classified['module']:
537
567
            if config[name]:
538
 
                if not module:
539
 
                    # missing module, will be provided by apps.openerp.com
540
 
                    to_install_missing_names.append(name[lm:])
541
 
                elif module.state == 'uninstalled':
542
 
                    # local module, to be installed
543
 
                    to_install_ids.append(module.id)
 
568
                to_install.append((name[lm:], module))
544
569
            else:
545
570
                if module and module.state in ('installed', 'to upgrade'):
546
571
                    to_uninstall_ids.append(module.id)
547
572
 
548
573
        if to_uninstall_ids:
549
574
            ir_module.button_immediate_uninstall(cr, uid, to_uninstall_ids, context=context)
550
 
        if to_install_ids:
551
 
            ir_module.button_immediate_install(cr, uid, to_install_ids, context=context)
552
575
 
553
 
        if to_install_missing_names:
554
 
            return {
555
 
                'type': 'ir.actions.client',
556
 
                'tag': 'apps',
557
 
                'params': {'modules': to_install_missing_names},
558
 
            }
 
576
        action = self._install_modules(cr, uid, to_install, context=context)
 
577
        if action:
 
578
            return action
559
579
 
560
580
        # After the uninstall/install calls, the self.pool is no longer valid.
561
581
        # So we reach into the RegistryManager directly.