diff --git a/odoo/modules/db.py b/odoo/modules/db.py index 3a432f0fecb..e37317288ae 100644 --- a/odoo/modules/db.py +++ b/odoo/modules/db.py @@ -75,12 +75,33 @@ def initialize(cr): # Install recursively all auto-installing modules while True: - cr.execute("""SELECT m.name FROM ir_module_module m WHERE m.auto_install AND state != 'to install' - AND NOT EXISTS ( - SELECT 1 FROM ir_module_module_dependency d JOIN ir_module_module mdep ON (d.name = mdep.name) - WHERE d.module_id = m.id AND mdep.state != 'to install' - )""") + # this selects all the auto_install modules whose auto_install_required + # deps are marked as to install + cr.execute(""" + SELECT m.name FROM ir_module_module m + WHERE m.auto_install + AND state != 'to install' + AND NOT EXISTS ( + SELECT 1 FROM ir_module_module_dependency d + JOIN ir_module_module mdep ON (d.name = mdep.name) + WHERE d.module_id = m.id + AND d.auto_install_required + AND mdep.state != 'to install' + )""") to_auto_install = [x[0] for x in cr.fetchall()] + # however if the module has non-required deps we need to install + # those, so merge-in the modules which have a dependen*t* which is + # *either* to_install or in to_auto_install and merge it in? + cr.execute(""" + SELECT d.name FROM ir_module_module_dependency d + JOIN ir_module_module m ON (d.module_id = m.id) + JOIN ir_module_module mdep ON (d.name = mdep.name) + WHERE (m.state = 'to install' OR m.name = any(%s)) + -- don't re-mark marked modules + AND NOT (mdep.state = 'to install' OR mdep.name = any(%s)) + """, [to_auto_install, to_auto_install]) + to_auto_install.extend(x[0] for x in cr.fetchall()) + if not to_auto_install: break cr.execute("""UPDATE ir_module_module SET state='to install' WHERE name in %s""", (tuple(to_auto_install),)) diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py index e256711e06f..c9ff470833f 100644 --- a/odoo/modules/loading.py +++ b/odoo/modules/loading.py @@ -377,22 +377,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False): _check_module_names(cr, itertools.chain(tools.config['init'], tools.config['update'])) - # auto-install module second pass: recursive bit in db.py handles - # auto_install modules with no dependencies or where all - # dependencies are auto_install, couldn't get it to work with - # non-required auto_install deps so here - cr.execute(""" - SELECT m.name FROM ir_module_module m - WHERE m.auto_install - AND m.state != 'installed' - AND NOT EXISTS ( - SELECT 1 FROM ir_module_module_dependency d - JOIN ir_module_module mdep ON (d.name = mdep.name) - WHERE d.module_id = m.id - AND d.auto_install_required - AND mdep.state NOT IN ('installed', 'to install') - )""") - module_names = [k for k, v in tools.config['init'].items() if v] + [x[0] for x in cr.fetchall()] + module_names = [k for k, v in tools.config['init'].items() if v] if module_names: modules = Module.search([('state', '=', 'uninstalled'), ('name', 'in', module_names)]) if modules: