@@ -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,19 @@ 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
+ if version_gte ("saas~14.5" ):
491
+ # We must delay until the modules actually exists. They are added by the auto discovery process.
492
+ if not if_installed or modules_installed (cr , * if_installed ):
493
+ ENVIRON ["__modules_auto_discovery_force_installs" ].add (module )
494
+ else :
495
+ _force_install_module (cr , module , if_installed )
496
+
497
+
498
+ def _force_install_module (cr , module , if_installed = None ):
499
+ # Low level implementation
500
+ # Needs the module to exist in the database
501
+ _assert_modules_exists (cr , module , * if_installed or ())
491
502
subquery = ""
492
503
subparams = ()
493
504
if if_installed :
@@ -582,7 +593,7 @@ def force_install_module(cr, module, if_installed=None):
582
593
)
583
594
for (mod ,) in cr .fetchall ():
584
595
_logger .debug ("auto install module %r due to module %r being force installed" , mod , module )
585
- force_install_module (cr , mod )
596
+ _force_install_module (cr , mod )
586
597
587
598
# TODO handle module exclusions
588
599
@@ -622,7 +633,7 @@ def new_module_dep(cr, module, new_dep):
622
633
if mod_state in INSTALLED_MODULE_STATES :
623
634
# Module was installed, need to install all its deps, recursively,
624
635
# to make sure the new dep is installed
625
- force_install_module (cr , module )
636
+ _force_install_module (cr , module )
626
637
627
638
628
639
def remove_module_deps (cr , module , old_deps ):
@@ -726,7 +737,7 @@ def trigger_auto_install(cr, module):
726
737
727
738
cr .execute (query , [module , INSTALLED_MODULE_STATES ])
728
739
if cr .rowcount :
729
- force_install_module (cr , module )
740
+ _force_install_module (cr , module )
730
741
return True
731
742
return False
732
743
@@ -852,6 +863,7 @@ def _force_upgrade_of_fresh_module(cr, module, init, version):
852
863
# Low level implementation
853
864
# Force module state to be in `to upgrade`.
854
865
# Needed for migration script execution. See http://git.io/vnF7f
866
+ _assert_modules_exists (cr , module )
855
867
cr .execute (
856
868
"""
857
869
UPDATE ir_module_module
@@ -917,8 +929,11 @@ def _trigger_auto_discovery(cr):
917
929
_set_module_countries (cr , module , countries )
918
930
module_auto_install (cr , module , auto_install )
919
931
920
- if module in force_installs :
921
- force_install_module (cr , module )
932
+ if force_installs :
933
+ _assert_modules_exists (cr , * force_installs )
934
+
935
+ for module in force_installs :
936
+ _force_install_module (cr , module )
922
937
923
938
for module , (init , version ) in ENVIRON ["__modules_auto_discovery_force_upgrades" ].items ():
924
939
_force_upgrade_of_fresh_module (cr , module , init , version )
0 commit comments