Skip to content

Commit

Permalink
[PORT] module_change_auto_install from 15.0 to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 8, 2022
1 parent 8ce4e9b commit 85750dc
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 40 deletions.
2 changes: 1 addition & 1 deletion module_change_auto_install/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Change auto installable modules",
"summary": "Customize auto installables modules by configuration",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Tools",
"maintainers": ["legalsylvain"],
"author": "GRAP, Odoo Community Association (OCA)",
Expand Down
15 changes: 15 additions & 0 deletions module_change_auto_install/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-10-13 13:04+0000\n"
"PO-Revision-Date: 2022-10-13 13:04+0000\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"
90 changes: 59 additions & 31 deletions module_change_auto_install/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,84 @@
from odoo.tools import config

_logger = logging.getLogger(__name__)
_original_load_information_from_description_file = (
modules.module.load_information_from_description_file
)
_original_load_manifest = modules.module.load_manifest


def split_strip(s):
"""Split string and strip each component sep by comma
def _get_modules_dict_auto_install_config(config_value):
"""Given a configuration parameter name, return a dict of
{module_name: modules_list or False}
>>> split_strip("foo, bar,")
['foo', 'bar']
if the odoo.cfg file contains
modules_auto_install_enabled =
web_responsive:web,
base_technical_features:,
point_of_sale:sale/purchase,
account_usability
>>> split_strip('modules_auto_install_enabled')
{
'web_responsive': ['web'],
'base_technical_features': [],
'point_of_sale': ['sale', 'purchase'],
'account_usability': False,
}
>>> split_strip("")
[]
>>> split_strip(None)
[]
"""
s = (s or "").strip(" ,")
if not s:
return []
return [x.strip() for x in s.split(",")]
res = {}
config_value = (config_value or "").strip(" ,")
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 _overload_load_information_from_description_file(module, mod_path=None):
res = _original_load_information_from_description_file(module, mod_path=None)
def _overload_load_manifest(module, mod_path=None):

res = _original_load_manifest(module, mod_path=None)
auto_install = res.get("auto_install", False)

modules_auto_install_enabled = split_strip(
modules_auto_install_enabled_dict = _get_modules_dict_auto_install_config(
config.get("modules_auto_install_enabled")
)
modules_auto_install_disabled = split_strip(
modules_auto_install_disabled_dict = _get_modules_dict_auto_install_config(
config.get("modules_auto_install_disabled")
)

if auto_install and module in modules_auto_install_disabled:
_logger.info("Module '%s' has been marked as not auto installable." % module)
if auto_install and module in modules_auto_install_disabled_dict.keys():
_logger.info("Module '%s' has been marked as NOT auto installable." % module)
res["auto_install"] = False

if not auto_install and module in modules_auto_install_enabled:
_logger.info("Module '%s' has been marked as auto installable." % module)
res["auto_install"] = set(res["depends"])
if not auto_install and module in modules_auto_install_enabled_dict.keys():
specific_dependencies = modules_auto_install_enabled_dict.get(module)
if type(specific_dependencies) is bool:
# Classical case
_logger.info("Module '%s' has been marked as auto installable." % module)
res["auto_install"] = set(res["depends"])
else:
if specific_dependencies:
_logger.info(
"Module '%s' has been marked as auto installable if '%s' are installed"
% (module, ",".join(specific_dependencies))
)
else:
_logger.info(
"Module '%s' has been marked as auto installable in ALL CASES."
% module
)

res["auto_install"] = set(specific_dependencies)

return res


def post_load():
_logger.info("Applying patch module_change_auto_intall")
modules.module.load_information_from_description_file = (
_overload_load_information_from_description_file
)
modules.load_information_from_description_file = (
_overload_load_information_from_description_file
)
_logger.info("Aplying patch module_change_auto_intall ...")
modules.module.load_manifest = _overload_load_manifest
modules.load_manifest = _overload_load_manifest
42 changes: 34 additions & 8 deletions module_change_auto_install/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,44 @@
server_wide_modules = web,module_change_auto_install
modules_auto_install_disabled = partner_autocomplete,iap,mail_bot,account_edi,account_edi_facturx,account_edi_ubl
modules_auto_install_disabled =
partner_autocomplete,
iap,
mail_bot
modules_auto_install_enabled = web_responsive,web_no_bubble,base_technical_features,disable_odoo_online,account_menu
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-block:: 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.addons.module_change_auto_install.patch: Module 'account_edi' has been marked as not auto installable.
INFO db_name odoo.addons.module_change_auto_install.patch: Module 'account_edi_facturx' has been marked as not auto installable.
INFO db_name odoo.addons.module_change_auto_install.patch: Module 'account_edi_ubl' has been marked as not auto installable.
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-block:: shell
modules_auto_install_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.
1 change: 1 addition & 0 deletions module_change_auto_install/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
30 changes: 30 additions & 0 deletions module_change_auto_install/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2015-2017 Camptocamp SA
# Copyright 2020 Onestein (<https://www.onestein.eu>)
# 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,
)

# from ..models.base import disable_changeset


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)

0 comments on commit 85750dc

Please sign in to comment.