summaryrefslogtreecommitdiff
path: root/odoo/modules/module.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2018-12-11 13:57:49 +0000
committerXavier Morel <xmo@odoo.com>2019-05-07 11:44:26 +0000
commit2cc7f0dd49a6be1920cef232e6c010fbafa68270 (patch)
treee62d6e2fac0f0bc24ffb3e8a58f90368462fa0c7 /odoo/modules/module.py
parentb9ec98357159621f8f8152c23025d1120cde2013 (diff)
[IMP] core: allow auto_install restriction on a subset of dependencies
Currently, auto_install is triggered when all dependencies get installed, but there are cases where one would want such trigger on only a subset thereof. e.g. we want `website_sale_dashboard` to auto-install when `website_sale` is installed. Currently, it requires `web_dashboard` to also be auto-installed otherwise `website_sale_dashboard` would "wait" for both dependencies to be explicitly installed before the auto-install triggers. That's despite `web_dashboard` not being very useful on its own. More generally this is an issue with technical modules which need to be marked as auto_install so as not to block e.g. bridge modules from automatically installing. This change allows setting `auto_install` to a subset of `depends`: * if auto_install is set to `False`, the module does not get automatically installed (no change in semantics) * if auto_install is set to `True`, the module gets automatically installed if and only if all its dependencies are installed (also no change in semantics) * if auto_install is set to a list of dependencies, the module will be installed when all *these* dependencies are installed, other dependencies (excluded from auto_install) will be installed alongside as a consequence * auto_install can be set to an empty list, in this case the module will always be automatically installed regardless of its dependencies (and will force their installation). So after this change, `web_dashboard`'s auto_install can be set to `False` (such that it's not installed if no module defining dashboards is installed) and `website_sale_dashboard`'s manifest can be edited to: 'auto_install': ['website_sale'] possibilities: # no automatic installation 'depends': ['a', 'b'], 'auto_install': False # automatic installation if both a and b are installed 'depends': ['a', 'b'], 'auto_install': True # automatic installation if both a and b are installed (explicit) 'depends': ['a', 'b'], 'auto_install': ['a', 'b'] # automatic installation if b is installed, a will get forcefully # installed if it isn't yet 'depends': ['a', 'b'], 'auto_install': ['b'] # always automatically installed, will cause the installation of # its dependencies even if they're not marked explicitly 'depends': ['a', 'b'], 'auto_install': [] Task 1851328 closes odoo/odoo#29431 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo/modules/module.py')
-rw-r--r--odoo/modules/module.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/odoo/modules/module.py b/odoo/modules/module.py
index 378812f1036..9160717bfb9 100644
--- a/odoo/modules/module.py
+++ b/odoo/modules/module.py
@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import ast
-import functools
+import collections
import imp
import importlib
import inspect
@@ -341,9 +341,23 @@ def load_information_from_description_file(module, mod_path=None):
readme_text = tools.file_open(readme_path[0]).read()
info['description'] = readme_text
- if 'active' in info:
- # 'active' has been renamed 'auto_install'
- info['auto_install'] = info['active']
+ # auto_install is set to `False` if disabled, and a set of
+ # auto_install dependencies otherwise. That way, we can set
+ # auto_install: [] to always auto_install a module regardless of its
+ # dependencies
+ auto_install = info.get('auto_install', info.get('active', False))
+ if isinstance(auto_install, collections.Iterable):
+ info['auto_install'] = set(auto_install)
+ non_dependencies = info['auto_install'].difference(info['depends'])
+ assert not non_dependencies,\
+ "auto_install triggers must be dependencies, found " \
+ "non-dependencies [%s] for module %s" % (
+ ', '.join(non_dependencies), module
+ )
+ elif auto_install:
+ info['auto_install'] = set(info['depends'])
+ else:
+ info['auto_install'] = False
info['version'] = adapt_version(info['version'])
return info