@@ -476,7 +476,7 @@ def _up(table, old, new):
476
476
cr .execute ("DELETE FROM ir_module_module_dependency WHERE name=%s" , [old ])
477
477
cr .execute ("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s" , [mod_ids [old ]])
478
478
if state in INSTALLED_MODULE_STATES :
479
- force_install_module (cr , into )
479
+ _force_install_module (cr , into )
480
480
481
481
482
482
def force_install_module (cr , module , if_installed = None ):
@@ -486,8 +486,20 @@ def force_install_module(cr, module, if_installed=None):
486
486
:param str module: name of the module to install
487
487
:param list(str) or None if_installed: only force the install when these modules are
488
488
already installed
489
- :return str: the *original* state of the module
490
489
"""
490
+ version = _caller_version ()
491
+ if version_gte ("saas~14.5" ):
492
+ # We must delay until the modules actually exists. They are added by the auto discovery process.
493
+ if not if_installed or modules_installed (cr , * if_installed ):
494
+ ENVIRON ["__modules_auto_discovery_force_installs" ].add (module )
495
+ return None
496
+ return _force_install_module (cr , module , if_installed )
497
+
498
+
499
+ def _force_install_module (cr , module , if_installed = None ):
500
+ # Low level implementation
501
+ # Needs the module to exist in the database
502
+ _assert_modules_exists (cr , module )
491
503
subquery = ""
492
504
subparams = ()
493
505
if if_installed :
@@ -582,7 +594,7 @@ def force_install_module(cr, module, if_installed=None):
582
594
)
583
595
for (mod ,) in cr .fetchall ():
584
596
_logger .debug ("auto install module %r due to module %r being force installed" , mod , module )
585
- force_install_module (cr , mod )
597
+ _force_install_module (cr , mod )
586
598
587
599
# TODO handle module exclusions
588
600
@@ -622,7 +634,7 @@ def new_module_dep(cr, module, new_dep):
622
634
if mod_state in INSTALLED_MODULE_STATES :
623
635
# Module was installed, need to install all its deps, recursively,
624
636
# to make sure the new dep is installed
625
- force_install_module (cr , module )
637
+ _force_install_module (cr , module )
626
638
627
639
628
640
def remove_module_deps (cr , module , old_deps ):
@@ -726,7 +738,7 @@ def trigger_auto_install(cr, module):
726
738
727
739
cr .execute (query , [module , INSTALLED_MODULE_STATES ])
728
740
if cr .rowcount :
729
- force_install_module (cr , module )
741
+ _force_install_module (cr , module )
730
742
return True
731
743
return False
732
744
@@ -918,7 +930,7 @@ def _trigger_auto_discovery(cr):
918
930
module_auto_install (cr , module , auto_install )
919
931
920
932
if module in force_installs :
921
- force_install_module (cr , module )
933
+ _force_install_module (cr , module )
922
934
923
935
for module , (init , version ) in ENVIRON ["__modules_auto_discovery_force_upgrades" ].items ():
924
936
_force_upgrade_of_fresh_module (cr , module , init , version )
0 commit comments