@@ -167,15 +167,19 @@ def load_module_graph(
167
167
module_cursor_query_count = env .cr .sql_log_count
168
168
module_extra_query_count = odoo .sql_db .sql_counter
169
169
170
- needs_update = update_module and package .state in ("to install" , "to upgrade" )
170
+ update_operation = (
171
+ 'install' if package .state == 'to install' else
172
+ 'upgrade' if package .state == 'to upgrade' else
173
+ 'reinit' if module_name in registry ._reinit_modules else
174
+ None
175
+ ) if update_module else None
171
176
module_log_level = logging .DEBUG
172
- if needs_update :
177
+ if update_operation :
173
178
module_log_level = logging .INFO
174
179
_logger .log (module_log_level , 'Loading module %s (%d/%d)' , module_name , index , module_count )
175
180
176
- new_install = package .state == 'to install'
177
- if needs_update :
178
- if not new_install or package .name in registry ._force_upgrade_scripts :
181
+ if update_operation :
182
+ if update_operation == 'upgrade' or module_name in registry ._force_upgrade_scripts :
179
183
if package .name != 'base' :
180
184
registry ._setup_models__ (env .cr )
181
185
migrations .migrate_module (package , 'pre' )
@@ -184,7 +188,7 @@ def load_module_graph(
184
188
185
189
load_openerp_module (package .name )
186
190
187
- if new_install :
191
+ if update_operation == 'install' :
188
192
py_module = sys .modules ['odoo.addons.%s' % (module_name ,)]
189
193
pre_init = package .manifest .get ('pre_init_hook' )
190
194
if pre_init :
@@ -193,12 +197,12 @@ def load_module_graph(
193
197
194
198
model_names = registry .load (package )
195
199
196
- if needs_update :
200
+ if update_operation :
197
201
model_names = registry .descendants (model_names , '_inherit' , '_inherits' )
198
202
models_updated |= set (model_names )
199
203
models_to_check -= set (model_names )
200
204
registry ._setup_models__ (env .cr )
201
- registry .init_models (env .cr , model_names , {'module' : package .name }, new_install )
205
+ registry .init_models (env .cr , model_names , {'module' : package .name }, update_operation == 'install' )
202
206
elif package .state != 'to remove' :
203
207
# The current module has simply been loaded. The models extended by this module
204
208
# and for which we updated the schema, must have their schema checked again.
@@ -208,24 +212,25 @@ def load_module_graph(
208
212
model_names = registry .descendants (model_names , '_inherit' , '_inherits' )
209
213
models_to_check |= set (model_names ) & models_updated
210
214
211
- if needs_update :
215
+ if update_operation :
212
216
# Can't put this line out of the loop: ir.module.module will be
213
217
# registered by init_models() above.
214
218
module = env ['ir.module.module' ].browse (module_id )
215
219
module ._check ()
216
220
217
221
idref : dict = {}
218
222
219
- if new_install : # 'to install'
223
+ if update_operation == ' install':
220
224
load_data (env , idref , 'init' , kind = 'data' , package = package )
221
225
if install_demo and package .demo_installable :
222
226
package .demo = load_demo (env , package , idref , 'init' )
223
- else : # 'to upgrade'
227
+ else : # 'upgrade' or 'reinit '
224
228
# upgrading the module information
225
229
module .write (module .get_values_from_terp (package .manifest ))
226
- load_data (env , idref , 'update' , kind = 'data' , package = package )
230
+ mode = 'update' if update_operation == 'upgrade' else 'init'
231
+ load_data (env , idref , mode , kind = 'data' , package = package )
227
232
if package .demo :
228
- package .demo = load_demo (env , package , idref , 'update' )
233
+ package .demo = load_demo (env , package , idref , mode )
229
234
env .cr .execute ('UPDATE ir_module_module SET demo = %s WHERE id = %s' , (package .demo , module_id ))
230
235
module .invalidate_model (['demo' ])
231
236
@@ -238,12 +243,12 @@ def load_module_graph(
238
243
if package .name is not None :
239
244
registry ._init_modules .add (package .name )
240
245
241
- if needs_update :
242
- if new_install :
246
+ if update_operation :
247
+ if update_operation == 'install' :
243
248
post_init = package .manifest .get ('post_init_hook' )
244
249
if post_init :
245
250
getattr (py_module , post_init )(env )
246
- else : # 'to upgrade'
251
+ elif update_operation == ' upgrade':
247
252
# validate the views that have not been checked yet
248
253
env ['ir.ui.view' ]._validate_module_views (module_name )
249
254
@@ -278,12 +283,12 @@ def load_module_graph(
278
283
test_queries = 0
279
284
test_results = None
280
285
281
- update_from_config = tools .config ['update' ] or tools .config ['init' ]
282
- if tools .config ['test_enable' ] and (needs_update or not update_from_config ):
286
+ update_from_config = tools .config ['update' ] or tools .config ['init' ] or tools . config [ 'reinit' ]
287
+ if tools .config ['test_enable' ] and (update_operation or not update_from_config ):
283
288
from odoo .tests import loader # noqa: PLC0415
284
289
suite = loader .make_suite ([module_name ], 'at_install' )
285
290
if suite .countTestCases ():
286
- if not needs_update :
291
+ if not update_operation :
287
292
registry ._setup_models__ (env .cr )
288
293
registry .check_null_constraints (env .cr )
289
294
# Python tests
@@ -345,6 +350,7 @@ def load_modules(
345
350
update_module : bool = False ,
346
351
upgrade_modules : Collection [str ] = (),
347
352
install_modules : Collection [str ] = (),
353
+ reinit_modules : Collection [str ] = (),
348
354
new_db_demo : bool = False ,
349
355
) -> None :
350
356
""" Load the modules for a registry object that has just been created. This
@@ -354,6 +360,7 @@ def load_modules(
354
360
:param update_module: Whether to update (install, upgrade, or uninstall) modules. Defaults to ``False``
355
361
:param upgrade_modules: A collection of module names to upgrade.
356
362
:param install_modules: A collection of module names to install.
363
+ :param reinit_modules: A collection of module names to reinitialize.
357
364
:param new_db_demo: Whether to install demo data for new database. Defaults to ``False``
358
365
"""
359
366
initialize_sys_path ()
@@ -372,6 +379,8 @@ def load_modules(
372
379
return
373
380
_logger .info ("init db" )
374
381
modules_db .initialize (cr )
382
+ elif 'base' in reinit_modules :
383
+ registry ._reinit_modules .add ('base' )
375
384
376
385
if 'base' in upgrade_modules :
377
386
cr .execute ("update ir_module_module set state=%s where name=%s and state=%s" , ('to upgrade' , 'base' , 'installed' ))
@@ -429,6 +438,11 @@ def load_modules(
429
438
if modules :
430
439
modules .button_upgrade ()
431
440
441
+ if reinit_modules :
442
+ modules = Module .search ([('state' , 'in' , ('installed' , 'to upgrade' )), ('name' , 'in' , tuple (reinit_modules ))])
443
+ reinit_modules = modules .downstream_dependencies (exclude_states = ('uninstalled' , 'uninstallable' , 'to remove' , 'to install' )) + modules
444
+ registry ._reinit_modules .update (m for m in reinit_modules .mapped ('name' ) if m not in graph ._imported_modules )
445
+
432
446
env .flush_all ()
433
447
cr .execute ("update ir_module_module set state=%s where name=%s" , ('installed' , 'base' ))
434
448
Module .invalidate_model (['state' ])
0 commit comments