diff --git a/module_change_auto_install/README.rst b/module_change_auto_install/README.rst new file mode 100644 index 00000000000..7df89b60bb9 --- /dev/null +++ b/module_change_auto_install/README.rst @@ -0,0 +1,209 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=============================== +Change auto installable modules +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:162ad195483bc21079128fc8075e1cf29eba3e177cffd0fbfa8d42f28a27ceab + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/19.0/module_change_auto_install + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-module_change_auto_install + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +In odoo, by default some modules are marked as auto installable by the +``auto_install`` key present in the manifest. + +- This feature is very useful for "glue" modules that allow two modules + to work together. (A typical example is ``sale_stock`` which allows + ``sale`` and ``stock`` modules to work together). +- However, Odoo SA also marks some modules as auto installable, even + though this is not technically required. This can happen for modules + the company wants to promote like ``iap``, modules with a big wow + effect like ``partner_autocomplete``, or some modules they consider + useful by default like ``account_edi``. See the discussion: + https://github.com/odoo/odoo/issues/71190 + +This module allows to change by configuration, the list of auto +installable modules, adding or removing some modules to auto install. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +You don't have to install this module. To make the features working : + +- make the module ``module_change_auto_install`` available in your + addons path +- either update your ``odoo.cfg`` or set the environment variables + following the "Configure" section + +Configuration +============= + +- Edit your ``odoo.cfg`` configuration file: +- Add the module ``module_change_auto_install`` in the + ``server_wide_modules`` list. +- (optional) Add a new entry ``modules_disabled`` beneath a new section + ``[module_change_auto_install]`` to mark a list of modules as NOT + auto installable. The environment variable + ``ODOO_MODULES_AUTO_INSTALL_DISABLED`` can also be set. +- (optional) Add a new entry ``modules_enabled`` beneath a new section + ``[module_change_auto_install]`` to mark a list of modules as auto + installable. This feature can be usefull for companies that are + hosting a lot of Odoo instances for many customers, and want some + modules to be always installed. The environment variable + ``ODOO_MODULES_AUTO_INSTALL_ENABLED`` can also be set. + +The values in the configuration file takes precedence over the +environment variable values. + +**Typical Settings** + +.. code:: cfg + + server_wide_modules = web,module_change_auto_install + + [module_change_auto_install] + modules_disabled = + partner_autocomplete, + iap, + mail_bot + + modules_enabled = + web_responsive:web, + base_technical_features, + disable_odoo_online, + account_usability + +When using environment variables, the same configuration is: + +.. code:: shell + + export ODOO_MODULES_AUTO_INSTALL_DISABLED=partner_autocomplete,iap,mail_bot + export ODOO_MODULES_AUTO_INSTALL_ENABLED=web_responsive:web,base_technical_features,disable_odoo_online,account_usability + +Run your instance and check logs. Modules that has been altered should +be present in your log, at the load of your instance: + +.. code:: shell + + INFO db_name odoo.addons.module_change_auto_install.patch: Module 'iap' has been marked as NOT auto installable. + INFO db_name odoo.addons.module_change_auto_install.patch: Module 'mail_bot' has been marked as NOT auto installable. + INFO db_name odoo.addons.module_change_auto_install.patch: Module 'partner_autocomplete' has been marked as NOT auto installable. + INFO db_name odoo.modules.loading: 42 modules loaded in 0.32s, 0 queries (+0 extra) + +**Advanced Configuration Possibilities** + +if your ``odoo.cfg`` file contains the following configuration: + +.. code:: cfg + + [module_change_auto_install] + modules_enabled = + account_usability, + web_responsive:web, + base_technical_features:, + point_of_sale:sale/purchase + +The behaviour will be the following: + +- ``account_usability`` module will be installed as soon as all the + default dependencies are installed. (here ``account``) +- ``web_responsive`` module will be installed as soon as ``web`` is + installed. (Althought ``web_responsive`` depends on ``web`` and + ``mail``) +- ``base_technical_features`` will be ALWAYS installed +- ``point_of_sale`` module will be installed as soon as ``sale`` and + ``purchase`` module are installed. + +When using environment variables, the same configuration is: + +.. code:: shell + + export ODOO_MODULES_AUTO_INSTALL_ENABLED=account_usability,web_responsive:web,base_technical_features:,point_of_sale:sale/purchase + +Development +=========== + +If you upgrade your odoo Instance from a major version to another, using +the OCA Free Software project "OpenUpgrade", you can also use this +module during the upgrade process, to avoid the installation of useless +new modules. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* GRAP + +Contributors +------------ + +- Sylvain LE GAL + +- XCG Consulting, part of `Orbeet `__: + + - Vincent Hatakeyama + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/module_change_auto_install/__init__.py b/module_change_auto_install/__init__.py new file mode 100644 index 00000000000..2e653d695c9 --- /dev/null +++ b/module_change_auto_install/__init__.py @@ -0,0 +1 @@ +from .patch import post_load diff --git a/module_change_auto_install/__manifest__.py b/module_change_auto_install/__manifest__.py new file mode 100644 index 00000000000..92534d516ba --- /dev/null +++ b/module_change_auto_install/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Change auto installable modules", + "summary": "Customize auto installables modules by configuration", + "version": "19.0.1.0.0", + "category": "Tools", + "maintainers": ["legalsylvain"], + "author": "GRAP, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/server-tools", + "installable": True, + "depends": ["base"], + "post_load": "post_load", + "license": "AGPL-3", +} diff --git a/module_change_auto_install/i18n/ca.po b/module_change_auto_install/i18n/ca.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_change_auto_install/i18n/fr.po b/module_change_auto_install/i18n/fr.po new file mode 100644 index 00000000000..e69de29bb2d diff --git a/module_change_auto_install/i18n/it.po b/module_change_auto_install/i18n/it.po new file mode 100644 index 00000000000..8af45f7b878 --- /dev/null +++ b/module_change_auto_install/i18n/it.po @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" diff --git a/module_change_auto_install/i18n/module_change_auto_install.pot b/module_change_auto_install/i18n/module_change_auto_install.pot new file mode 100644 index 00000000000..aadee09bfed --- /dev/null +++ b/module_change_auto_install/i18n/module_change_auto_install.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/module_change_auto_install/patch.py b/module_change_auto_install/patch.py new file mode 100644 index 00000000000..e4dcf83e689 --- /dev/null +++ b/module_change_auto_install/patch.py @@ -0,0 +1,127 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import configparser +import logging +import os + +from odoo.modules.module import Manifest +from odoo.tools import config + +_logger = logging.getLogger(__name__) +_original_init = Manifest.__init__ + + +def _get_modules_dict_auto_install_config(config_value): + """Given a configuration parameter name, return a dict of + {module_name: modules_list or False} + + if the odoo.cfg file contains + [module_change_auto_install] + modules_enabled = + web_responsive:web, + base_technical_features:, + point_of_sale:sale/purchase, + account_usability + + >>> split_strip('modules_enabled') + { + 'web_responsive': ['web'], + 'base_technical_features': [], + 'point_of_sale': ['sale', 'purchase'], + 'account_usability': False, + } + + + """ + res = {} + config_value = (config_value or "").strip(" ,") + if config_value: + config_list = [x.strip() for x in config_value.split(",")] + for item in config_list: + if ":" in item: + res[item.split(":")[0]] = ( + item.split(":")[1] and item.split(":")[1].split("/") or [] + ) + else: + res[item] = True + return res + + +def _get_modules_auto_install_enabled_dict(): + return _get_modules_dict_auto_install_config( + config.get( + "module_change_auto_install.modules_enabled", + os.environ.get("ODOO_MODULES_AUTO_INSTALL_ENABLED"), + ) + ) + + +def _get_modules_auto_install_disabled_dict(): + return _get_modules_dict_auto_install_config( + config.get( + "module_change_auto_install.modules_disabled", + os.environ.get("ODOO_MODULES_AUTO_INSTALL_DISABLED"), + ) + ) + + +def _get_auto_install_flag(self): + modules_auto_install_enabled_dict = _get_modules_auto_install_enabled_dict() + modules_auto_install_disabled_dict = _get_modules_auto_install_disabled_dict() + auto_install = self._Manifest__manifest_cached["auto_install"] + module = self.name + + if auto_install and module in modules_auto_install_disabled_dict.keys(): + _logger.info(f"Module '{module}' has been marked as NOT auto installable.") + return False + + if not auto_install and module in modules_auto_install_enabled_dict.keys(): + specific_dependencies = modules_auto_install_enabled_dict.get(module) + if isinstance(specific_dependencies, bool): + # Classical case + _logger.info(f"Module '{module}' has been marked as auto installable.") + return set(self._Manifest__manifest_cached["depends"]) + else: + if specific_dependencies: + _logger.info( + "Module '{}' has been marked as auto installable if '{}' " + "are installed".format(module, ",".join(specific_dependencies)) + ) + else: + _logger.info( + f"Module '{module}' has been marked as auto installable in " + f"ALL CASES." + ) + + return set(specific_dependencies) + return auto_install + + +def _patched_init(self, *, path: str, manifest_content: dict): + _original_init(self, path=path, manifest_content=manifest_content) + # Post-process before cached_property kicks in + self.auto_install = _get_auto_install_flag(self) + if "auto_install" in self._Manifest__manifest_cached: + self._Manifest__manifest_cached["auto_install"] = self.auto_install + + +def _load_module_change_auto_install_options(rcfile): + """Load custom [module_change_auto_install] section into config.""" + cp = configparser.ConfigParser() + cp.read([rcfile]) + + if cp.has_section("module_change_auto_install"): + for key, value in cp.items("module_change_auto_install"): + # Store with prefix to avoid collisions + config[f"module_change_auto_install.{key}"] = value + _logger.debug("Loaded custom option %s=%s", key, value) + + +def post_load(): + _logger.info("Applying patch module_change_auto_install ...") + Manifest.__init__ = _patched_init + rcfile = config.get("config") + if rcfile: + _load_module_change_auto_install_options(rcfile) diff --git a/module_change_auto_install/pyproject.toml b/module_change_auto_install/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/module_change_auto_install/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/module_change_auto_install/readme/CONFIGURE.md b/module_change_auto_install/readme/CONFIGURE.md new file mode 100644 index 00000000000..38bd38c55bb --- /dev/null +++ b/module_change_auto_install/readme/CONFIGURE.md @@ -0,0 +1,80 @@ +- Edit your `odoo.cfg` configuration file: +- Add the module `module_change_auto_install` in the + `server_wide_modules` list. +- (optional) Add a new entry `modules_disabled` beneath a new section `[module_change_auto_install]` to mark a + list of modules as NOT auto installable. + The environment variable ``ODOO_MODULES_AUTO_INSTALL_DISABLED`` can also be set. +- (optional) Add a new entry `modules_enabled` beneath a new section `[module_change_auto_install]` to mark a + list of modules as auto installable. This feature can be usefull for + companies that are hosting a lot of Odoo instances for many customers, + and want some modules to be always installed. + The environment variable ``ODOO_MODULES_AUTO_INSTALL_ENABLED`` can also be set. + +The values in the configuration file takes precedence over the environment variable +values. + +**Typical Settings** + +``` cfg +server_wide_modules = web,module_change_auto_install + +[module_change_auto_install] +modules_disabled = + partner_autocomplete, + iap, + mail_bot + +modules_enabled = + web_responsive:web, + base_technical_features, + disable_odoo_online, + account_usability +``` + +When using environment variables, the same configuration is: + +``` shell +export ODOO_MODULES_AUTO_INSTALL_DISABLED=partner_autocomplete,iap,mail_bot +export ODOO_MODULES_AUTO_INSTALL_ENABLED=web_responsive:web,base_technical_features,disable_odoo_online,account_usability +``` + + +Run your instance and check logs. Modules that has been altered should +be present in your log, at the load of your instance: + +``` shell +INFO db_name odoo.addons.module_change_auto_install.patch: Module 'iap' has been marked as NOT auto installable. +INFO db_name odoo.addons.module_change_auto_install.patch: Module 'mail_bot' has been marked as NOT auto installable. +INFO db_name odoo.addons.module_change_auto_install.patch: Module 'partner_autocomplete' has been marked as NOT auto installable. +INFO db_name odoo.modules.loading: 42 modules loaded in 0.32s, 0 queries (+0 extra) +``` + +**Advanced Configuration Possibilities** + +if your `odoo.cfg` file contains the following configuration: + +``` cfg +[module_change_auto_install] +modules_enabled = + account_usability, + web_responsive:web, + base_technical_features:, + point_of_sale:sale/purchase +``` + +The behaviour will be the following: + +- `account_usability` module will be installed as soon as all the + default dependencies are installed. (here `account`) +- `web_responsive` module will be installed as soon as `web` is + installed. (Althought `web_responsive` depends on `web` and `mail`) +- `base_technical_features` will be ALWAYS installed +- `point_of_sale` module will be installed as soon as `sale` and + `purchase` module are installed. + +When using environment variables, the same configuration is: + +``` shell +export ODOO_MODULES_AUTO_INSTALL_ENABLED=account_usability,web_responsive:web,base_technical_features:,point_of_sale:sale/purchase +``` + diff --git a/module_change_auto_install/readme/CONTRIBUTORS.md b/module_change_auto_install/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..d907ba4a5d9 --- /dev/null +++ b/module_change_auto_install/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Sylvain LE GAL \<\> +- XCG Consulting, part of [Orbeet](https://orbeet.io/): + + - Vincent Hatakeyama \<\> diff --git a/module_change_auto_install/readme/DESCRIPTION.md b/module_change_auto_install/readme/DESCRIPTION.md new file mode 100644 index 00000000000..c1fbd71e29b --- /dev/null +++ b/module_change_auto_install/readme/DESCRIPTION.md @@ -0,0 +1,15 @@ +In odoo, by default some modules are marked as auto installable by the +`auto_install` key present in the manifest. + +- This feature is very useful for "glue" modules that allow two modules + to work together. (A typical example is `sale_stock` which allows + `sale` and `stock` modules to work together). +- However, Odoo SA also marks some modules as auto installable, even + though this is not technically required. This can happen for modules + the company wants to promote like `iap`, modules with a big wow effect + like `partner_autocomplete`, or some modules they consider useful by + default like `account_edi`. See the discussion: + + +This module allows to change by configuration, the list of auto +installable modules, adding or removing some modules to auto install. diff --git a/module_change_auto_install/readme/DEVELOP.md b/module_change_auto_install/readme/DEVELOP.md new file mode 100644 index 00000000000..5ea36d27d1c --- /dev/null +++ b/module_change_auto_install/readme/DEVELOP.md @@ -0,0 +1,4 @@ +If you upgrade your odoo Instance from a major version to another, using +the OCA Free Software project "OpenUpgrade", you can also use this +module during the upgrade process, to avoid the installation of useless +new modules. diff --git a/module_change_auto_install/readme/INSTALL.md b/module_change_auto_install/readme/INSTALL.md new file mode 100644 index 00000000000..449583f6e81 --- /dev/null +++ b/module_change_auto_install/readme/INSTALL.md @@ -0,0 +1,5 @@ +You don't have to install this module. To make the features working : + +- make the module `module_change_auto_install` available in your addons + path +- either update your `odoo.cfg` or set the environment variables following the "Configure" section diff --git a/module_change_auto_install/static/description/icon.png b/module_change_auto_install/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/module_change_auto_install/static/description/icon.png differ diff --git a/module_change_auto_install/static/description/index.html b/module_change_auto_install/static/description/index.html new file mode 100644 index 00000000000..bfc67ab53aa --- /dev/null +++ b/module_change_auto_install/static/description/index.html @@ -0,0 +1,543 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Change auto installable modules

+ +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

In odoo, by default some modules are marked as auto installable by the +auto_install key present in the manifest.

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

This module allows to change by configuration, the list of auto +installable modules, adding or removing some modules to auto install.

+

Table of contents

+ +
+

Installation

+

You don’t have to install this module. To make the features working :

+
    +
  • make the module module_change_auto_install available in your +addons path
  • +
  • either update your odoo.cfg or set the environment variables +following the “Configure” section
  • +
+
+
+

Configuration

+
    +
  • Edit your odoo.cfg configuration file:
  • +
  • Add the module module_change_auto_install in the +server_wide_modules list.
  • +
  • (optional) Add a new entry modules_disabled beneath a new section +[module_change_auto_install] to mark a list of modules as NOT +auto installable. The environment variable +ODOO_MODULES_AUTO_INSTALL_DISABLED can also be set.
  • +
  • (optional) Add a new entry modules_enabled beneath a new section +[module_change_auto_install] to mark a list of modules as auto +installable. This feature can be usefull for companies that are +hosting a lot of Odoo instances for many customers, and want some +modules to be always installed. The environment variable +ODOO_MODULES_AUTO_INSTALL_ENABLED can also be set.
  • +
+

The values in the configuration file takes precedence over the +environment variable values.

+

Typical Settings

+
+server_wide_modules = web,module_change_auto_install
+
+[module_change_auto_install]
+modules_disabled =
+    partner_autocomplete,
+    iap,
+    mail_bot
+
+modules_enabled =
+    web_responsive:web,
+    base_technical_features,
+    disable_odoo_online,
+    account_usability
+
+

When using environment variables, the same configuration is:

+
+export ODOO_MODULES_AUTO_INSTALL_DISABLED=partner_autocomplete,iap,mail_bot
+export ODOO_MODULES_AUTO_INSTALL_ENABLED=web_responsive:web,base_technical_features,disable_odoo_online,account_usability
+
+

Run your instance and check logs. Modules that has been altered should +be present in your log, at the load of your instance:

+
+INFO db_name odoo.addons.module_change_auto_install.patch: Module 'iap' has been marked as NOT auto installable.
+INFO db_name odoo.addons.module_change_auto_install.patch: Module 'mail_bot' has been marked as NOT auto installable.
+INFO db_name odoo.addons.module_change_auto_install.patch: Module 'partner_autocomplete' has been marked as NOT auto installable.
+INFO db_name odoo.modules.loading: 42 modules loaded in 0.32s, 0 queries (+0 extra)
+
+

Advanced Configuration Possibilities

+

if your odoo.cfg file contains the following configuration:

+
+[module_change_auto_install]
+modules_enabled =
+    account_usability,
+    web_responsive:web,
+    base_technical_features:,
+    point_of_sale:sale/purchase
+
+

The behaviour will be the following:

+
    +
  • account_usability module will be installed as soon as all the +default dependencies are installed. (here account)
  • +
  • web_responsive module will be installed as soon as web is +installed. (Althought web_responsive depends on web and +mail)
  • +
  • base_technical_features will be ALWAYS installed
  • +
  • point_of_sale module will be installed as soon as sale and +purchase module are installed.
  • +
+

When using environment variables, the same configuration is:

+
+export ODOO_MODULES_AUTO_INSTALL_ENABLED=account_usability,web_responsive:web,base_technical_features:,point_of_sale:sale/purchase
+
+
+
+

Development

+

If you upgrade your odoo Instance from a major version to another, using +the OCA Free Software project “OpenUpgrade”, you can also use this +module during the upgrade process, to avoid the installation of useless +new modules.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/server-tools project on GitHub.

+

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

+
+
+
+
+ + diff --git a/module_change_auto_install/tests/__init__.py b/module_change_auto_install/tests/__init__.py new file mode 100644 index 00000000000..f7aa81860ba --- /dev/null +++ b/module_change_auto_install/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_module +from . import test_patch diff --git a/module_change_auto_install/tests/test_module.py b/module_change_auto_install/tests/test_module.py new file mode 100644 index 00000000000..a2a265b1231 --- /dev/null +++ b/module_change_auto_install/tests/test_module.py @@ -0,0 +1,31 @@ +# Copyright 2015-2017 Camptocamp SA +# Copyright 2020 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + +from odoo.addons.module_change_auto_install.patch import ( + _get_modules_dict_auto_install_config, +) + + +class TestModule(TransactionCase): + _EXPECTED_RESULTS = { + "web_responsive": {"web_responsive": True}, + "sale, purchase,": {"sale": True, "purchase": True}, + "web_responsive:web,base_technical_features:," + "point_of_sale:sale/purchase,account_usability": { + "web_responsive": ["web"], + "base_technical_features": [], + "point_of_sale": ["sale", "purchase"], + "account_usability": True, + }, + } + + def test_config_parsing(self): + for k, v in self._EXPECTED_RESULTS.items(): + self.assertEqual(_get_modules_dict_auto_install_config(k), v) + + def test_get_module_info(self): + self.env["ir.module.module"].get_module_info("account").get("countries", []) + self.env["ir.module.module"].get_module_info("BlaBla").get("countries", []) diff --git a/module_change_auto_install/tests/test_patch.py b/module_change_auto_install/tests/test_patch.py new file mode 100644 index 00000000000..01a134f0c11 --- /dev/null +++ b/module_change_auto_install/tests/test_patch.py @@ -0,0 +1,76 @@ +import logging +import os +import tempfile +from unittest.mock import patch + +from odoo.modules.module import Manifest +from odoo.tests.common import TransactionCase +from odoo.tools import config + +import odoo.addons.module_change_auto_install as mcai + +_logger = logging.getLogger(__name__) + + +def make_manifest(name, depends=None, auto_install=False): + tmpdir = tempfile.mkdtemp() + module_path = os.path.join(tmpdir, name) + os.makedirs(module_path, exist_ok=True) + + manifest_content = { + "name": name, + "author": "Author", + "license": "AGPL-3", + "depends": depends or [], + "auto_install": auto_install, + } + return Manifest(path=module_path, manifest_content=manifest_content) + + +class TestModuleChangeAutoInstall(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Apply patch once for all tests + mcai.post_load() + + def test_default_auto_install(self): + m = make_manifest("test_module", ["base"], auto_install=False) + self.assertFalse(m._Manifest__manifest_cached["auto_install"]) + + @patch.dict( + config.options, + { + "module_change_auto_install.modules_disabled": "test_module", + }, + ) + def test_disabled_module(self): + m = make_manifest("test_module", ["base"], auto_install=True) + self.assertTrue(m._Manifest__manifest_cached["auto_install"] is False) + + @patch.dict( + config.options, {"module_change_auto_install.modules_enabled": "test_module"} + ) + def test_enabled_module_unconditional(self): + m = make_manifest("test_module", ["base"], auto_install=False) + # Should return its dependencies as auto-install condition + self.assertEqual(m._Manifest__manifest_cached["auto_install"], set(["base"])) + + @patch.dict( + config.options, + { + "module_change_auto_install.modules_enabled": "test_module:dep1/dep2", + }, + ) + def test_enabled_module_with_specific_dependencies(self): + m = make_manifest("test_module", ["base"], auto_install=False) + self.assertEqual( + m._Manifest__manifest_cached["auto_install"], set(["dep1", "dep2"]) + ) + + @patch.dict( + config.options, {"module_change_auto_install.modules_enabled": "test_module:"} + ) + def test_enabled_module_all_cases(self): + m = make_manifest("test_module", ["base"], auto_install=False) + self.assertEqual(m._Manifest__manifest_cached["auto_install"], set())