Skip to content

Commit 086cfb3

Browse files
committed
[MIG] module_change_auto_install: Migration to 19.0
1 parent bf6b607 commit 086cfb3

File tree

8 files changed

+203
-95
lines changed

8 files changed

+203
-95
lines changed

module_change_auto_install/README.rst

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ Change auto installable modules
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-tools/tree/18.0/module_change_auto_install
24+
:target: https://github.com/OCA/server-tools/tree/19.0/module_change_auto_install
2525
:alt: OCA/server-tools
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-module_change_auto_install
27+
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-module_change_auto_install
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
3434

3535
In odoo, by default some modules are marked as auto installable by the
3636
``auto_install`` key present in the manifest.
3737

38-
- This feature is very useful for "glue" modules that allow two modules
39-
to work together. (A typical example is ``sale_stock`` which allows
40-
``sale`` and ``stock`` modules to work together).
41-
- However, Odoo SA also marks some modules as auto installable, even
42-
though this is not technically required. This can happen for modules
43-
the company wants to promote like ``iap``, modules with a big wow
44-
effect like ``partner_autocomplete``, or some modules they consider
45-
useful by default like ``account_edi``. See the discussion:
46-
https://github.com/odoo/odoo/issues/71190
38+
- This feature is very useful for "glue" modules that allow two modules
39+
to work together. (A typical example is ``sale_stock`` which allows
40+
``sale`` and ``stock`` modules to work together).
41+
- However, Odoo SA also marks some modules as auto installable, even
42+
though this is not technically required. This can happen for modules
43+
the company wants to promote like ``iap``, modules with a big wow
44+
effect like ``partner_autocomplete``, or some modules they consider
45+
useful by default like ``account_edi``. See the discussion:
46+
https://github.com/odoo/odoo/issues/71190
4747

4848
This module allows to change by configuration, the list of auto
4949
installable modules, adding or removing some modules to auto install.
@@ -58,25 +58,27 @@ Installation
5858

5959
You don't have to install this module. To make the features working :
6060

61-
- make the module ``module_change_auto_install`` available in your
62-
addons path
63-
- either update your ``odoo.cfg`` or set the environment variables
64-
following the "Configure" section
61+
- make the module ``module_change_auto_install`` available in your
62+
addons path
63+
- either update your ``odoo.cfg`` or set the environment variables
64+
following the "Configure" section
6565

6666
Configuration
6767
=============
6868

69-
- Edit your ``odoo.cfg`` configuration file:
70-
- Add the module ``module_change_auto_install`` in the
71-
``server_wide_modules`` list.
72-
- (optional) Add a new entry ``modules_auto_install_disabled`` to mark a
73-
list of modules as NOT auto installable. The environment variable
74-
``ODOO_MODULES_AUTO_INSTALL_DISABLED`` can also be set.
75-
- (optional) Add a new entry ``modules_auto_install_enabled`` to mark a
76-
list of modules as auto installable. This feature can be usefull for
77-
companies that are hosting a lot of Odoo instances for many customers,
78-
and want some modules to be always installed. The environment variable
79-
``ODOO_MODULES_AUTO_INSTALL_ENABLED`` can also be set.
69+
- Edit your ``odoo.cfg`` configuration file:
70+
- Add the module ``module_change_auto_install`` in the
71+
``server_wide_modules`` list.
72+
- (optional) Add a new entry ``modules_disabled`` beneath a new section
73+
``[module_change_auto_install]`` to mark a list of modules as NOT
74+
auto installable. The environment variable
75+
``ODOO_MODULES_AUTO_INSTALL_DISABLED`` can also be set.
76+
- (optional) Add a new entry ``modules_enabled`` beneath a new section
77+
``[module_change_auto_install]`` to mark a list of modules as auto
78+
installable. This feature can be usefull for companies that are
79+
hosting a lot of Odoo instances for many customers, and want some
80+
modules to be always installed. The environment variable
81+
``ODOO_MODULES_AUTO_INSTALL_ENABLED`` can also be set.
8082

8183
The values in the configuration file takes precedence over the
8284
environment variable values.
@@ -87,12 +89,13 @@ environment variable values.
8789
8890
server_wide_modules = web,module_change_auto_install
8991
90-
modules_auto_install_disabled =
92+
[module_change_auto_install]
93+
modules_disabled =
9194
partner_autocomplete,
9295
iap,
9396
mail_bot
9497
95-
modules_auto_install_enabled =
98+
modules_enabled =
9699
web_responsive:web,
97100
base_technical_features,
98101
disable_odoo_online,
@@ -121,22 +124,23 @@ if your ``odoo.cfg`` file contains the following configuration:
121124

122125
.. code:: cfg
123126
124-
modules_auto_install_enabled =
127+
[module_change_auto_install]
128+
modules_enabled =
125129
account_usability,
126130
web_responsive:web,
127131
base_technical_features:,
128132
point_of_sale:sale/purchase
129133
130134
The behaviour will be the following:
131135

132-
- ``account_usability`` module will be installed as soon as all the
133-
default dependencies are installed. (here ``account``)
134-
- ``web_responsive`` module will be installed as soon as ``web`` is
135-
installed. (Althought ``web_responsive`` depends on ``web`` and
136-
``mail``)
137-
- ``base_technical_features`` will be ALWAYS installed
138-
- ``point_of_sale`` module will be installed as soon as ``sale`` and
139-
``purchase`` module are installed.
136+
- ``account_usability`` module will be installed as soon as all the
137+
default dependencies are installed. (here ``account``)
138+
- ``web_responsive`` module will be installed as soon as ``web`` is
139+
installed. (Althought ``web_responsive`` depends on ``web`` and
140+
``mail``)
141+
- ``base_technical_features`` will be ALWAYS installed
142+
- ``point_of_sale`` module will be installed as soon as ``sale`` and
143+
``purchase`` module are installed.
140144

141145
When using environment variables, the same configuration is:
142146

@@ -158,7 +162,7 @@ Bug Tracker
158162
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
159163
In case of trouble, please check there if your issue has already been reported.
160164
If you spotted it first, help us to smash it by providing a detailed and welcomed
161-
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20module_change_auto_install%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
165+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20module_change_auto_install%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
162166

163167
Do not contact contributors directly about support or help with technical issues.
164168

@@ -173,11 +177,11 @@ Authors
173177
Contributors
174178
------------
175179

176-
- Sylvain LE GAL <https://twitter.com/legalsylvain>
180+
- Sylvain LE GAL <https://twitter.com/legalsylvain>
177181

178-
- XCG Consulting, part of `Orbeet <https://orbeet.io/>`__:
182+
- XCG Consulting, part of `Orbeet <https://orbeet.io/>`__:
179183

180-
- Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>
184+
- Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>
181185

182186
Maintainers
183187
-----------
@@ -200,6 +204,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
200204

201205
|maintainer-legalsylvain|
202206

203-
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/module_change_auto_install>`_ project on GitHub.
207+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/module_change_auto_install>`_ project on GitHub.
204208

205209
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

module_change_auto_install/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Change auto installable modules",
77
"summary": "Customize auto installables modules by configuration",
8-
"version": "18.0.1.0.3",
8+
"version": "19.0.1.0.0",
99
"category": "Tools",
1010
"maintainers": ["legalsylvain"],
1111
"author": "GRAP, Odoo Community Association (OCA)",

module_change_auto_install/patch.py

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5+
import configparser
56
import logging
67
import os
78

8-
from odoo import modules
9+
from odoo.modules.module import Manifest
910
from odoo.tools import config
1011

1112
_logger = logging.getLogger(__name__)
12-
_original_load_manifest = modules.module.load_manifest
13+
_original_init = Manifest.__init__
1314

1415

1516
def _get_modules_dict_auto_install_config(config_value):
1617
"""Given a configuration parameter name, return a dict of
1718
{module_name: modules_list or False}
1819
1920
if the odoo.cfg file contains
20-
21-
modules_auto_install_enabled =
21+
[module_change_auto_install]
22+
modules_enabled =
2223
web_responsive:web,
2324
base_technical_features:,
2425
point_of_sale:sale/purchase,
2526
account_usability
2627
27-
>>> split_strip('modules_auto_install_enabled')
28+
>>> split_strip('modules_enabled')
2829
{
2930
'web_responsive': ['web'],
3031
'base_technical_features': [],
@@ -36,49 +37,52 @@ def _get_modules_dict_auto_install_config(config_value):
3637
"""
3738
res = {}
3839
config_value = (config_value or "").strip(" ,")
39-
config_list = [x.strip() for x in config_value.split(",")]
40-
for item in config_list:
41-
if ":" in item:
42-
res[item.split(":")[0]] = (
43-
item.split(":")[1] and item.split(":")[1].split("/") or []
44-
)
45-
else:
46-
res[item] = True
40+
if config_value:
41+
config_list = [x.strip() for x in config_value.split(",")]
42+
for item in config_list:
43+
if ":" in item:
44+
res[item.split(":")[0]] = (
45+
item.split(":")[1] and item.split(":")[1].split("/") or []
46+
)
47+
else:
48+
res[item] = True
4749
return res
4850

4951

50-
def _overload_load_manifest(module, mod_path=None):
51-
res = _original_load_manifest(module, mod_path=None)
52-
if not res:
53-
# Specific case where a previously available module marked as auto installable
54-
# is NOT available in the addons path.
55-
# In that case, avoid to crash when trying to get 'depends' key.
56-
return res
57-
auto_install = res.get("auto_install", False)
58-
59-
modules_auto_install_enabled_dict = _get_modules_dict_auto_install_config(
52+
def _get_modules_auto_install_enabled_dict():
53+
return _get_modules_dict_auto_install_config(
6054
config.get(
61-
"modules_auto_install_enabled",
55+
"module_change_auto_install.modules_enabled",
6256
os.environ.get("ODOO_MODULES_AUTO_INSTALL_ENABLED"),
6357
)
6458
)
65-
modules_auto_install_disabled_dict = _get_modules_dict_auto_install_config(
59+
60+
61+
def _get_modules_auto_install_disabled_dict():
62+
return _get_modules_dict_auto_install_config(
6663
config.get(
67-
"modules_auto_install_disabled",
64+
"module_change_auto_install.modules_disabled",
6865
os.environ.get("ODOO_MODULES_AUTO_INSTALL_DISABLED"),
6966
)
7067
)
7168

69+
70+
def _get_auto_install_flag(self):
71+
modules_auto_install_enabled_dict = _get_modules_auto_install_enabled_dict()
72+
modules_auto_install_disabled_dict = _get_modules_auto_install_disabled_dict()
73+
auto_install = self.manifest_cached["auto_install"]
74+
module = self.name
75+
7276
if auto_install and module in modules_auto_install_disabled_dict.keys():
7377
_logger.info(f"Module '{module}' has been marked as NOT auto installable.")
74-
res["auto_install"] = False
78+
return False
7579

7680
if not auto_install and module in modules_auto_install_enabled_dict.keys():
7781
specific_dependencies = modules_auto_install_enabled_dict.get(module)
7882
if isinstance(specific_dependencies, bool):
7983
# Classical case
8084
_logger.info(f"Module '{module}' has been marked as auto installable.")
81-
res["auto_install"] = set(res["depends"])
85+
return set(self.manifest_cached["depends"])
8286
else:
8387
if specific_dependencies:
8488
_logger.info(
@@ -91,12 +95,33 @@ def _overload_load_manifest(module, mod_path=None):
9195
f"ALL CASES."
9296
)
9397

94-
res["auto_install"] = set(specific_dependencies)
98+
return set(specific_dependencies)
99+
return auto_install
95100

96-
return res
101+
102+
def _patched_init(self, *, path: str, manifest_content: dict):
103+
_original_init(self, path=path, manifest_content=manifest_content)
104+
# Post-process before cached_property kicks in
105+
self.auto_install = _get_auto_install_flag(self)
106+
if "auto_install" in self.manifest_cached:
107+
self.manifest_cached["auto_install"] = self.auto_install
108+
109+
110+
def _load_module_change_auto_install_options(rcfile):
111+
"""Load custom [module_change_auto_install] section into config."""
112+
cp = configparser.ConfigParser()
113+
cp.read([rcfile])
114+
115+
if cp.has_section("module_change_auto_install"):
116+
for key, value in cp.items("module_change_auto_install"):
117+
# Store with prefix to avoid collisions
118+
config[f"module_change_auto_install.{key}"] = value
119+
_logger.debug("Loaded custom option %s=%s", key, value)
97120

98121

99122
def post_load():
100123
_logger.info("Applying patch module_change_auto_install ...")
101-
modules.module.load_manifest = _overload_load_manifest
102-
modules.load_manifest = _overload_load_manifest
124+
Manifest.__init__ = _patched_init
125+
rcfile = config.get("config")
126+
if rcfile:
127+
_load_module_change_auto_install_options(rcfile)

module_change_auto_install/readme/CONFIGURE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
- Edit your `odoo.cfg` configuration file:
22
- Add the module `module_change_auto_install` in the
33
`server_wide_modules` list.
4-
- (optional) Add a new entry `modules_auto_install_disabled` to mark a
4+
- (optional) Add a new entry `modules_disabled` beneath a new section `[module_change_auto_install]` to mark a
55
list of modules as NOT auto installable.
66
The environment variable ``ODOO_MODULES_AUTO_INSTALL_DISABLED`` can also be set.
7-
- (optional) Add a new entry `modules_auto_install_enabled` to mark a
7+
- (optional) Add a new entry `modules_enabled` beneath a new section `[module_change_auto_install]` to mark a
88
list of modules as auto installable. This feature can be usefull for
99
companies that are hosting a lot of Odoo instances for many customers,
1010
and want some modules to be always installed.
@@ -18,12 +18,13 @@ values.
1818
``` cfg
1919
server_wide_modules = web,module_change_auto_install
2020
21-
modules_auto_install_disabled =
21+
[module_change_auto_install]
22+
modules_disabled =
2223
partner_autocomplete,
2324
iap,
2425
mail_bot
2526
26-
modules_auto_install_enabled =
27+
modules_enabled =
2728
web_responsive:web,
2829
base_technical_features,
2930
disable_odoo_online,
@@ -53,7 +54,8 @@ INFO db_name odoo.modules.loading: 42 modules loaded in 0.32s, 0 queries (+0 ext
5354
if your `odoo.cfg` file contains the following configuration:
5455

5556
``` cfg
56-
modules_auto_install_enabled =
57+
[module_change_auto_install]
58+
modules_enabled =
5759
account_usability,
5860
web_responsive:web,
5961
base_technical_features:,

0 commit comments

Comments
 (0)