Skip to content

Commit 7aacb38

Browse files
committed
[IMP] util/modules.py
Handle delayed install/upgrades in {rename,remove,merge}_module() closes #315 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent b68569c commit 7aacb38

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/util/modules.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from .exceptions import MigrationError, SleepyDeveloperError, UnknownModuleError
4747
from .fields import remove_field
4848
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
5050
from .models import delete_model
5151
from .orm import env, flush
5252
from .pg import SQLStr, column_exists, format_query, table_exists, target_of
@@ -310,6 +310,9 @@ def remove_module(cr, module):
310310
[mod_id] = cr.fetchone()
311311
cr.execute("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s", [mod_id])
312312

313+
ENVIRON["__modules_auto_discovery_force_installs"].discard(module)
314+
ENVIRON["__modules_auto_discovery_force_upgrades"].pop(module, None)
315+
313316

314317
def remove_theme(cr, theme, base_theme=None):
315318
"""
@@ -327,6 +330,9 @@ def remove_theme(cr, theme, base_theme=None):
327330
[mod_id] = cr.fetchone()
328331
cr.execute("DELETE FROM ir_model_data WHERE model='ir.module.module' AND res_id=%s", [mod_id])
329332

333+
ENVIRON["__modules_auto_discovery_force_installs"].discard(theme)
334+
ENVIRON["__modules_auto_discovery_force_upgrades"].pop(theme, None)
335+
330336

331337
def _update_view_key(cr, old, new):
332338
# update view key for renamed & merged modules, also handle multi-website
@@ -372,6 +378,14 @@ def rename_module(cr, old, new):
372378
[mod_new, mod_old, "base", "ir.module.module"],
373379
)
374380

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+
375389

376390
def merge_module(cr, old, into, update_dependers=True):
377391
"""
@@ -392,6 +406,21 @@ def merge_module(cr, old, into, update_dependers=True):
392406
cr.execute("SELECT name, id FROM ir_module_module WHERE name IN %s", [(old, into)])
393407
mod_ids = dict(cr.fetchall())
394408

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+
395424
if old not in mod_ids:
396425
# this can happen in case of temp modules added after a release if the database does not
397426
# know about this module, i.e: account_full_reconcile in 9.0

0 commit comments

Comments
 (0)