|
55 | 55 | INSTALLED_MODULE_STATES = ("installed", "to install", "to upgrade") |
56 | 56 | _logger = logging.getLogger(__name__) |
57 | 57 |
|
| 58 | +ENVIRON.setdefault("AUTO_DISCOVERY_RAN", False) |
| 59 | + |
58 | 60 | if version_gte("15.0"): |
59 | 61 | AUTO_INSTALL = os.getenv("UPG_AUTOINSTALL") |
60 | 62 | _NO_AUTOINSTALL = os.getenv("UPG_NO_AUTOINSTALL") |
@@ -553,6 +555,14 @@ def force_install_module(cr, module, if_installed=None, reason="it has been expl |
553 | 555 | if if_installed: |
554 | 556 | _assert_modules_exists(cr, *if_installed) |
555 | 557 | if not if_installed or modules_installed(cr, *if_installed): |
| 558 | + cr.execute("SELECT 1 FROM ir_module_module WHERE name = 'base' AND state != 'to upgrade'") |
| 559 | + if cr.rowcount: |
| 560 | + if not ENVIRON.get("AUTO_DISCOVERY_RAN"): |
| 561 | + # run the autodiscovery once to allow to force install _new_ modules |
| 562 | + _trigger_auto_discovery(cr) |
| 563 | + elif ENVIRON.get("AUTO_DISCOVERY_UPGRADE"): |
| 564 | + raise MigrationError("`force_install_module` can only be called from pre/post of `base`") |
| 565 | + return _force_install_module(cr, module, reason="{} (done outside of a major upgrade)".format(reason)) |
556 | 566 | ENVIRON["__modules_auto_discovery_force_installs"].add(module) |
557 | 567 | return None |
558 | 568 | else: |
@@ -995,6 +1005,8 @@ def _trigger_auto_discovery(cr): |
995 | 1005 | # Called by `base/0.0.0/post-modules-auto-discovery.py` script. |
996 | 1006 | # Use accumulated values for the auto_install and force_upgrade modules. |
997 | 1007 |
|
| 1008 | + ENVIRON["AUTO_DISCOVERY_RAN"] = True |
| 1009 | + |
998 | 1010 | force_installs = ENVIRON["__modules_auto_discovery_force_installs"] |
999 | 1011 |
|
1000 | 1012 | cr.execute( |
|
0 commit comments