Skip to content

Commit

Permalink
Merge pull request #18 from initOS/handle-auto-install-modules
Browse files Browse the repository at this point in the history
[FIX] Handle auto_install modules
  • Loading branch information
ortlam committed Oct 4, 2023
2 parents 13d2f8c + 4db9c48 commit 297c019
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/doblib/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.17.0"
VERSION = "0.17.1"
48 changes: 46 additions & 2 deletions src/doblib/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,45 @@ def install_all(self, db_name, modules):
force_demo=not without_demo,
)

def check_auto_install(self, db_name):
"""Install auto installable modules if the dependencies are installed"""
states = frozenset(("installed", "to install", "to upgrade"))

with self.env(db_name, False) as env:
domain = [("state", "=", "uninstalled"), ("auto_install", "=", True)]
modules = env["ir.module.module"].search(domain)
auto_install = {module: module.dependencies_id for module in modules}

to_install = env["ir.module.module"].browse()
new_module = True
while new_module:
new_module = False
for module, dependencies in auto_install.items():
if all(
dep.state in states or dep.depend_id in to_install
for dep in dependencies
):
to_install |= module
new_module = True

auto_install = {
mod: deps
for mod, deps in auto_install.items()
if mod not in to_install
}

if to_install:
utils.info("Installing auto_install modules")
to_install.button_immediate_install()

def update_checksums(self, db_name):
"""Only update the module checksums in the database"""
with self.env(db_name, False) as env:
model = env["ir.module.module"]
if hasattr(model, "_save_installed_checksums"):
utils.info("Updating module checksums")
model._save_installed_checksums()

def update_specific(
self, db_name, whitelist=None, blacklist=None, installed=False, listed=False
):
Expand Down Expand Up @@ -221,15 +260,20 @@ def update(self, args=None):
uninstalled = modules.difference(installed)

# Install all modules
utils.info("Installing all modules")
if uninstalled:
utils.info("Installing all modules")
self.install_all(db_name, uninstalled)

# Check for auto install modules
self.check_auto_install(db_name)

# Execute the pre update script
self._run_migration(db_name, "pre_update")

# Update all modules which aren't installed before
if args.all or args.listed or args.modules:
if initialized:
self.update_checksums(db_name)
elif args.all or args.listed or args.modules:
self.update_specific(
db_name,
whitelist=args.modules,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_update(env):
odoo.modules.db.is_initialized.return_value = False
env.update()
env._get_installed_modules.assert_not_called()
env.update_changed.assert_called_once()
env.update_changed.assert_not_called()

odoo.release.version_info = (15,)
odoo.modules.db.is_initialized.return_value = True
Expand Down

0 comments on commit 297c019

Please sign in to comment.