Skip to content

Commit 8df49d3

Browse files
committed
[FIX] util/modules.py: set module category at auto-discovery
When skipping the auto_install modules installation, we verify the module's category, so better set it. Part of odoo/upgrade#5261 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 7269ad5 commit 8df49d3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/util/modules.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
try:
1414
import odoo
15+
from odoo.modules.db import create_categories
1516
from odoo.tools.func import frame_codeinfo
1617
from odoo.tools.misc import topological_sort
1718

@@ -22,6 +23,7 @@
2223
except ImportError:
2324
import openerp as odoo
2425
from openerp.modules import load_information_from_description_file as get_manifest
26+
from openerp.modules.db import create_categories
2527
from openerp.tools.func import frame_codeinfo
2628

2729
try:
@@ -573,6 +575,7 @@ def module_auto_install(cr, module, auto_install):
573575
)
574576

575577
cr.execute("UPDATE ir_module_module SET auto_install = %s WHERE name = %s", [auto_install is not False, module])
578+
trigger_auto_install(cr, module)
576579

577580

578581
def trigger_auto_install(cr, module):
@@ -614,7 +617,12 @@ def trigger_auto_install(cr, module):
614617
return bool(cr.rowcount)
615618

616619

617-
def new_module(cr, module, deps=(), auto_install=False):
620+
def _set_module_category(cr, module, category):
621+
cid = create_categories(cr, category.split("/"))
622+
cr.execute("UPDATE ir_module_module SET category_id=%s WHERE name=%s", [cid, module])
623+
624+
625+
def new_module(cr, module, deps=(), auto_install=False, category=None):
618626
if deps:
619627
_assert_modules_exists(cr, *deps)
620628

@@ -633,11 +641,7 @@ def new_module(cr, module, deps=(), auto_install=False):
633641
cr.execute("DELETE FROM ir_module_module_dependency WHERE module_id = %s", [mod_id])
634642

635643
else:
636-
if deps and auto_install and not module.startswith("test_"):
637-
to_check = deps if auto_install is True else auto_install
638-
state = "to install" if modules_installed(cr, *to_check) else "uninstalled"
639-
else:
640-
state = "uninstalled"
644+
state = "uninstalled"
641645
cr.execute(
642646
"""
643647
INSERT INTO ir_module_module (name, state, demo)
@@ -659,6 +663,9 @@ def new_module(cr, module, deps=(), auto_install=False):
659663
for dep in deps:
660664
new_module_dep(cr, module, dep)
661665

666+
if category is not None:
667+
_set_module_category(cr, module, category)
668+
662669
module_auto_install(cr, module, auto_install)
663670

664671

@@ -735,18 +742,19 @@ def _trigger_auto_discovery(cr):
735742
graph = {}
736743
for module in odoo.modules.get_modules():
737744
manifest = get_manifest(module)
738-
graph[module] = (set(manifest["depends"]), manifest["auto_install"])
745+
graph[module] = (set(manifest["depends"]), manifest["auto_install"], manifest["category"])
739746

740747
for module in topological_sort({k: v[0] for k, v in graph.items()}):
741-
deps, auto_install = graph[module]
748+
deps, auto_install, category = graph[module]
742749
if module not in existing:
743-
new_module(cr, module, deps=deps, auto_install=auto_install)
750+
new_module(cr, module, deps=deps, auto_install=auto_install, category=category)
744751
else:
745752
current_deps = set(existing[module])
746753
plus = deps - current_deps
747754
minus = current_deps - deps
748755
if plus or minus:
749756
module_deps_diff(cr, module, plus=plus, minus=minus)
757+
_set_module_category(cr, module, category)
750758
module_auto_install(cr, module, auto_install)
751759

752760
if module in force_installs:

0 commit comments

Comments
 (0)