46
46
from .exceptions import MigrationError , SleepyDeveloperError , UnknownModuleError
47
47
from .fields import remove_field
48
48
from .helpers import _validate_model , table_of_model
49
- from .misc import on_CI , str2bool , version_gte
49
+ from .misc import on_CI , parse_version , str2bool , version_gte
50
50
from .models import delete_model
51
51
from .orm import env , flush
52
52
from .pg import SQLStr , column_exists , format_query , table_exists , target_of
@@ -310,6 +310,9 @@ def remove_module(cr, module):
310
310
[mod_id ] = cr .fetchone ()
311
311
cr .execute ("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s" , [mod_id ])
312
312
313
+ ENVIRON ["__modules_auto_discovery_force_installs" ].discard (module )
314
+ ENVIRON ["__modules_auto_discovery_force_upgrades" ].pop (module , None )
315
+
313
316
314
317
def remove_theme (cr , theme , base_theme = None ):
315
318
"""
@@ -327,6 +330,9 @@ def remove_theme(cr, theme, base_theme=None):
327
330
[mod_id ] = cr .fetchone ()
328
331
cr .execute ("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s" , [mod_id ])
329
332
333
+ ENVIRON ["__modules_auto_discovery_force_installs" ].discard (theme )
334
+ ENVIRON ["__modules_auto_discovery_force_upgrades" ].pop (theme , None )
335
+
330
336
331
337
def _update_view_key (cr , old , new ):
332
338
# update view key for renamed & merged modules, also handle multi-website
@@ -372,6 +378,14 @@ def rename_module(cr, old, new):
372
378
[mod_new , mod_old , "base" , "ir.module.module" ],
373
379
)
374
380
381
+ fi = ENVIRON ["__modules_auto_discovery_force_installs" ]
382
+ if old in fi :
383
+ fi .remove (old )
384
+ fi .add (new )
385
+ fu = ENVIRON ["__modules_auto_discovery_force_upgrades" ]
386
+ if old in fu :
387
+ fu [new ] = fu .pop (old )
388
+
375
389
376
390
def merge_module (cr , old , into , update_dependers = True ):
377
391
"""
@@ -392,6 +406,21 @@ def merge_module(cr, old, into, update_dependers=True):
392
406
cr .execute ("SELECT name, id FROM ir_module_module WHERE name IN %s" , [(old , into )])
393
407
mod_ids = dict (cr .fetchall ())
394
408
409
+ fi = ENVIRON ["__modules_auto_discovery_force_installs" ]
410
+ if old in fi :
411
+ fi .remove (old )
412
+ fi .add (into )
413
+ fu = ENVIRON ["__modules_auto_discovery_force_upgrades" ]
414
+ if old in fu :
415
+ if into not in fu :
416
+ fu [into ] = fu .pop (old )
417
+ else :
418
+ init = fu [old ][0 ] or fu [into ][0 ] # keep init flag
419
+ # keep the min version, this controls which upgrade scripts run
420
+ version = fu [old ][1 ] if parse_version (fu [old ][1 ]) < parse_version (fu [into ][1 ]) else fu [into ][1 ]
421
+ del fu [old ]
422
+ fu [into ] = (init , version )
423
+
395
424
if old not in mod_ids :
396
425
# this can happen in case of temp modules added after a release if the database does not
397
426
# know about this module, i.e: account_full_reconcile in 9.0
0 commit comments