[IMP] ir.module.module: change `active` flag to
authorVo Minh Thu <vmt@openerp.com>
Thu, 26 Jan 2012 16:40:49 +0000 (17:40 +0100)
committerVo Minh Thu <vmt@openerp.com>
Thu, 26 Jan 2012 16:40:49 +0000 (17:40 +0100)
`auto_installable`. An auto-installable module is a module automatically
installed by the OpenERP server as soon as its dependencies are
satisfied, without explicit user action.

bzr revid: vmt@openerp.com-20120126164049-smrcvrojy0b1z6f8

openerp/addons/base/__openerp__.py
openerp/addons/base/base.sql
openerp/addons/base/module/module.py
openerp/modules/db.py
openerp/modules/module.py

index ab9231b..c1bc500 100644 (file)
@@ -97,7 +97,7 @@
         # 'test/test_ir_cron.yml', # <-- These tests perform a roolback.
     ],
     'installable': True,
-    'active': True,
+    'auto_installable': True,
     'certificate': '0076807797149',
     "css": [ 'static/src/css/modules.css' ],
 }
index 31872b4..2b3bec3 100644 (file)
@@ -302,6 +302,7 @@ CREATE TABLE ir_module_module (
     web boolean DEFAULT FALSE,
     license character varying(32),
     sequence integer DEFAULT 100,
+    auto_installable boolean default False,
     primary key(id)
 );
 ALTER TABLE ir_module_module add constraint name_uniq unique (name);
index 34ed483..808a89f 100644 (file)
@@ -192,6 +192,10 @@ class module(osv.osv):
         'sequence': fields.integer('Sequence'),
         'dependencies_id': fields.one2many('ir.module.module.dependency',
             'module_id', 'Dependencies', readonly=True),
+        'auto_installable': fields.boolean('Auto Installable',
+            help='An auto-installable module is automatically installed by the '
+            'system when all its dependencies are satisfied. '
+            'If the module has no dependency, it is always installed.'),
         'state': fields.selection([
             ('uninstallable','Not Installable'),
             ('uninstalled','Not Installed'),
@@ -318,20 +322,27 @@ class module(osv.osv):
         return demo
 
     def button_install(self, cr, uid, ids, context=None):
-        model_obj = self.pool.get('ir.model.data')
+
+        # Mark the given modules to be installed.
         self.state_update(cr, uid, ids, 'to install', ['uninstalled'], context)
 
-        categ = model_obj.get_object(cr, uid, 'base', 'module_category_hidden_links', context=context)
-        todo = []
-        for mod in categ.module_ids:
-            if mod.state=='uninstalled':
-                ok = True
-                for dep in mod.dependencies_id:
-                    ok = ok and (dep.state in ('to install','installed'))
-                if ok:
-                    todo.append(mod.id)
-        if todo:
-            self.button_install(cr, uid, todo, context=context)
+        # Mark (recursively) the newly satisfied modules to also be installed:
+
+        # Select all auto-installable (but not yet installed) modules.
+        domain = [('state', '=', 'uninstalled'), ('auto_installable', '=', True),]
+        uninstalled_ids = self.search(cr, uid, domain, context=context)
+        uninstalled_modules = self.browse(cr, uid, uninstalled_ids, context=context)
+
+        # Keep those with all their dependencies satisfied.
+        def all_depencies_satisfied(m):
+            return all(x.state in ('to install', 'installed', 'to upgrade') for x in m.dependencies_id)
+        to_install_modules = filter(all_depencies_satisfied, uninstalled_modules)
+        to_install_ids = map(lambda m: m.id, to_install_modules)
+
+        # Mark them to be installed.
+        if to_install_ids:
+            self.button_install(cr, uid, to_install_ids, context=context)
+
         return dict(ACTION_DICT, name=_('Install'))
 
     def button_immediate_install(self, cr, uid, ids, context=None):
@@ -439,6 +450,7 @@ class module(osv.osv):
             'complexity': terp.get('complexity', ''),
             'sequence': terp.get('sequence', 100),
             'application': terp.get('application', False),
+            'auto_installable': terp.get('auto_installable', False),
         }
 
     # update the list of available packages
index a670a29..df25013 100644 (file)
@@ -66,7 +66,7 @@ def initialize(cr):
         category_id = create_categories(cr, categories)
 
         if info['installable']:
-            if info['active']:
+            if info['auto_installable'] and not info['depends']:
                 state = 'to install'
             else:
                 state = 'uninstalled'
@@ -75,11 +75,12 @@ def initialize(cr):
 
         cr.execute('INSERT INTO ir_module_module \
                 (author, website, name, shortdesc, description, \
-                    category_id, state, certificate, web, license, complexity, application, icon, sequence) \
-                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id', (
+                    category_id, auto_installable, state, certificate, web, license, complexity, application, icon, sequence) \
+                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id', (
             info['author'],
             info['website'], i, info['name'],
-            info['description'], category_id, state, info['certificate'],
+            info['description'], category_id,
+            info['auto_installable'], state, info['certificate'],
             info['web'],
             info['license'],
             info['complexity'], info['application'], info['icon'],
index b82597d..acf883c 100644 (file)
@@ -327,6 +327,7 @@ def load_information_from_description_file(module):
                 'description': '',
                 'icon': get_module_icon(module),
                 'installable': True,
+                'auto_installable': False,
                 'license': 'AGPL-3',
                 'name': False,
                 'post_load': None,