Skip to content

Commit 89f3790

Browse files
committed
Merge PR #3384 into 19.0
Signed-off-by StefanRijnhart
2 parents 36d97f7 + 494a9b7 commit 89f3790

File tree

19 files changed

+1144
-0
lines changed

19 files changed

+1144
-0
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
===============================
6+
Change auto installable modules
7+
===============================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:162ad195483bc21079128fc8075e1cf29eba3e177cffd0fbfa8d42f28a27ceab
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
22+
:alt: License: AGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
24+
:target: https://github.com/OCA/server-tools/tree/19.0/module_change_auto_install
25+
:alt: OCA/server-tools
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-module_change_auto_install
28+
:alt: Translate me on Weblate
29+
.. |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=19.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
In odoo, by default some modules are marked as auto installable by the
36+
``auto_install`` key present in the manifest.
37+
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
47+
48+
This module allows to change by configuration, the list of auto
49+
installable modules, adding or removing some modules to auto install.
50+
51+
**Table of contents**
52+
53+
.. contents::
54+
:local:
55+
56+
Installation
57+
============
58+
59+
You don't have to install this module. To make the features working :
60+
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
65+
66+
Configuration
67+
=============
68+
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.
82+
83+
The values in the configuration file takes precedence over the
84+
environment variable values.
85+
86+
**Typical Settings**
87+
88+
.. code:: cfg
89+
90+
server_wide_modules = web,module_change_auto_install
91+
92+
[module_change_auto_install]
93+
modules_disabled =
94+
partner_autocomplete,
95+
iap,
96+
mail_bot
97+
98+
modules_enabled =
99+
web_responsive:web,
100+
base_technical_features,
101+
disable_odoo_online,
102+
account_usability
103+
104+
When using environment variables, the same configuration is:
105+
106+
.. code:: shell
107+
108+
export ODOO_MODULES_AUTO_INSTALL_DISABLED=partner_autocomplete,iap,mail_bot
109+
export ODOO_MODULES_AUTO_INSTALL_ENABLED=web_responsive:web,base_technical_features,disable_odoo_online,account_usability
110+
111+
Run your instance and check logs. Modules that has been altered should
112+
be present in your log, at the load of your instance:
113+
114+
.. code:: shell
115+
116+
INFO db_name odoo.addons.module_change_auto_install.patch: Module 'iap' has been marked as NOT auto installable.
117+
INFO db_name odoo.addons.module_change_auto_install.patch: Module 'mail_bot' has been marked as NOT auto installable.
118+
INFO db_name odoo.addons.module_change_auto_install.patch: Module 'partner_autocomplete' has been marked as NOT auto installable.
119+
INFO db_name odoo.modules.loading: 42 modules loaded in 0.32s, 0 queries (+0 extra)
120+
121+
**Advanced Configuration Possibilities**
122+
123+
if your ``odoo.cfg`` file contains the following configuration:
124+
125+
.. code:: cfg
126+
127+
[module_change_auto_install]
128+
modules_enabled =
129+
account_usability,
130+
web_responsive:web,
131+
base_technical_features:,
132+
point_of_sale:sale/purchase
133+
134+
The behaviour will be the following:
135+
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.
144+
145+
When using environment variables, the same configuration is:
146+
147+
.. code:: shell
148+
149+
export ODOO_MODULES_AUTO_INSTALL_ENABLED=account_usability,web_responsive:web,base_technical_features:,point_of_sale:sale/purchase
150+
151+
Development
152+
===========
153+
154+
If you upgrade your odoo Instance from a major version to another, using
155+
the OCA Free Software project "OpenUpgrade", you can also use this
156+
module during the upgrade process, to avoid the installation of useless
157+
new modules.
158+
159+
Bug Tracker
160+
===========
161+
162+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
163+
In case of trouble, please check there if your issue has already been reported.
164+
If you spotted it first, help us to smash it by providing a detailed and welcomed
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**>`_.
166+
167+
Do not contact contributors directly about support or help with technical issues.
168+
169+
Credits
170+
=======
171+
172+
Authors
173+
-------
174+
175+
* GRAP
176+
177+
Contributors
178+
------------
179+
180+
- Sylvain LE GAL <https://twitter.com/legalsylvain>
181+
182+
- XCG Consulting, part of `Orbeet <https://orbeet.io/>`__:
183+
184+
- Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>
185+
186+
Maintainers
187+
-----------
188+
189+
This module is maintained by the OCA.
190+
191+
.. image:: https://odoo-community.org/logo.png
192+
:alt: Odoo Community Association
193+
:target: https://odoo-community.org
194+
195+
OCA, or the Odoo Community Association, is a nonprofit organization whose
196+
mission is to support the collaborative development of Odoo features and
197+
promote its widespread use.
198+
199+
.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px
200+
:target: https://github.com/legalsylvain
201+
:alt: legalsylvain
202+
203+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
204+
205+
|maintainer-legalsylvain|
206+
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.
208+
209+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .patch import post_load
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
2+
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
{
6+
"name": "Change auto installable modules",
7+
"summary": "Customize auto installables modules by configuration",
8+
"version": "19.0.1.0.0",
9+
"category": "Tools",
10+
"maintainers": ["legalsylvain"],
11+
"author": "GRAP, Odoo Community Association (OCA)",
12+
"website": "https://github.com/OCA/server-tools",
13+
"installable": True,
14+
"depends": ["base"],
15+
"post_load": "post_load",
16+
"license": "AGPL-3",
17+
}

module_change_auto_install/i18n/ca.po

Whitespace-only changes.

module_change_auto_install/i18n/fr.po

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
#
4+
msgid ""
5+
msgstr ""
6+
"Project-Id-Version: Odoo Server 17.0\n"
7+
"Report-Msgid-Bugs-To: \n"
8+
"Last-Translator: Automatically generated\n"
9+
"Language-Team: none\n"
10+
"Language: it\n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
#
4+
msgid ""
5+
msgstr ""
6+
"Project-Id-Version: Odoo Server 18.0\n"
7+
"Report-Msgid-Bugs-To: \n"
8+
"Last-Translator: \n"
9+
"Language-Team: \n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: \n"
13+
"Plural-Forms: \n"
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
2+
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
import configparser
6+
import logging
7+
import os
8+
9+
from odoo.modules.module import Manifest
10+
from odoo.tools import config
11+
12+
_logger = logging.getLogger(__name__)
13+
_original_init = Manifest.__init__
14+
15+
16+
def _get_modules_dict_auto_install_config(config_value):
17+
"""Given a configuration parameter name, return a dict of
18+
{module_name: modules_list or False}
19+
20+
if the odoo.cfg file contains
21+
[module_change_auto_install]
22+
modules_enabled =
23+
web_responsive:web,
24+
base_technical_features:,
25+
point_of_sale:sale/purchase,
26+
account_usability
27+
28+
>>> split_strip('modules_enabled')
29+
{
30+
'web_responsive': ['web'],
31+
'base_technical_features': [],
32+
'point_of_sale': ['sale', 'purchase'],
33+
'account_usability': False,
34+
}
35+
36+
37+
"""
38+
res = {}
39+
config_value = (config_value or "").strip(" ,")
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
49+
return res
50+
51+
52+
def _get_modules_auto_install_enabled_dict():
53+
return _get_modules_dict_auto_install_config(
54+
config.get(
55+
"module_change_auto_install.modules_enabled",
56+
os.environ.get("ODOO_MODULES_AUTO_INSTALL_ENABLED"),
57+
)
58+
)
59+
60+
61+
def _get_modules_auto_install_disabled_dict():
62+
return _get_modules_dict_auto_install_config(
63+
config.get(
64+
"module_change_auto_install.modules_disabled",
65+
os.environ.get("ODOO_MODULES_AUTO_INSTALL_DISABLED"),
66+
)
67+
)
68+
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__manifest_cached["auto_install"]
74+
module = self.name
75+
76+
if auto_install and module in modules_auto_install_disabled_dict.keys():
77+
_logger.info(f"Module '{module}' has been marked as NOT auto installable.")
78+
return False
79+
80+
if not auto_install and module in modules_auto_install_enabled_dict.keys():
81+
specific_dependencies = modules_auto_install_enabled_dict.get(module)
82+
if isinstance(specific_dependencies, bool):
83+
# Classical case
84+
_logger.info(f"Module '{module}' has been marked as auto installable.")
85+
return set(self._Manifest__manifest_cached["depends"])
86+
else:
87+
if specific_dependencies:
88+
_logger.info(
89+
"Module '{}' has been marked as auto installable if '{}' "
90+
"are installed".format(module, ",".join(specific_dependencies))
91+
)
92+
else:
93+
_logger.info(
94+
f"Module '{module}' has been marked as auto installable in "
95+
f"ALL CASES."
96+
)
97+
98+
return set(specific_dependencies)
99+
return auto_install
100+
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__manifest_cached:
107+
self._Manifest__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)
120+
121+
122+
def post_load():
123+
_logger.info("Applying patch module_change_auto_install ...")
124+
Manifest.__init__ = _patched_init
125+
rcfile = config.get("config")
126+
if rcfile:
127+
_load_module_change_auto_install_options(rcfile)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)