Skip to content

Commit 7269ad5

Browse files
committed
[IMP] util/modules.py: add option to not install auto_install modules
The R&D teams having the propensity to mark a lot of functional modules as `auto_install` to palliate an UX flaw regarding feature discovery, upgraded databases ends with more and more modules that customers don't necessary want. This profusion of installed modules can now be avoided by setting the `UPG_NO_AUTOINSTALL` environment variable. Note that real link modules are still installed. Part-of: odoo/upgrade#5261
1 parent f6ad930 commit 7269ad5

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/util/modules.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
from .exceptions import MigrationError, SleepyDeveloperError
3434
from .fields import remove_field
3535
from .helpers import _validate_model, table_of_model
36-
from .misc import on_CI, version_gte
36+
from .misc import on_CI, str2bool, version_gte
3737
from .models import delete_model
3838
from .orm import env, flush
3939
from .pg import column_exists, table_exists, target_of
40-
from .records import remove_menus, remove_records, remove_view, replace_record_references_batch
40+
from .records import ref, remove_menus, remove_records, remove_view, replace_record_references_batch
4141

4242
INSTALLED_MODULE_STATES = ("installed", "to install", "to upgrade")
43+
NO_AUTOINSTALL = str2bool(os.getenv("UPG_NO_AUTOINSTALL", "0")) if version_gte("15.0") else False
4344
_logger = logging.getLogger(__name__)
4445

4546
# python3 shims
@@ -450,6 +451,13 @@ def force_install_module(cr, module, if_installed=None):
450451
if column_exists(cr, "ir_module_module_dependency", "auto_install_required"):
451452
dep_match = "AND d.auto_install_required = TRUE AND e.auto_install_required = TRUE"
452453

454+
cat_match = ""
455+
if NO_AUTOINSTALL:
456+
# even if we skip auto installs, we still need to auto install the real link-modules.
457+
# those are in the "Hidden" category
458+
hidden = ref(cr, "base.module_category_hidden")
459+
cat_match = cr.mogrify("AND on_me.category_id = %s", [hidden]).decode()
460+
453461
cr.execute(
454462
"""
455463
SELECT on_me.name
@@ -461,12 +469,13 @@ def force_install_module(cr, module, if_installed=None):
461469
AND on_me.state = 'uninstalled'
462470
AND on_me.auto_install = TRUE
463471
{}
472+
{}
464473
GROUP BY on_me.name
465474
HAVING
466475
-- are all dependencies (to be) installed?
467476
array_agg(its_deps.state)::text[] <@ %s
468477
""".format(
469-
dep_match
478+
dep_match, cat_match
470479
),
471480
[toinstall, list(INSTALLED_MODULE_STATES)],
472481
)
@@ -572,6 +581,13 @@ def trigger_auto_install(cr, module):
572581
if column_exists(cr, "ir_module_module_dependency", "auto_install_required"):
573582
dep_match = "d.auto_install_required = true"
574583

584+
cat_match = "true"
585+
if NO_AUTOINSTALL:
586+
# even if we skip auto installs, we still need to auto install the real link-modules.
587+
# those are in the "Hidden" category
588+
hidden = ref(cr, "base.module_category_hidden")
589+
cat_match = cr.mogrify("m.category_id = %s", [hidden]).decode()
590+
575591
query = """
576592
WITH to_install AS (
577593
SELECT m.id
@@ -582,6 +598,7 @@ def trigger_auto_install(cr, module):
582598
AND m.state = 'uninstalled'
583599
AND m.auto_install = true
584600
AND {}
601+
AND {}
585602
GROUP BY m.id
586603
HAVING bool_and(md.state IN %s)
587604
)
@@ -590,7 +607,7 @@ def trigger_auto_install(cr, module):
590607
FROM to_install t
591608
WHERE t.id = m.id
592609
""".format(
593-
dep_match
610+
dep_match, cat_match
594611
)
595612

596613
cr.execute(query, [module, INSTALLED_MODULE_STATES])

0 commit comments

Comments
 (0)