Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions module_auto_update/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==================
Module Auto Update
==================
Expand All @@ -17,7 +13,7 @@ Module Auto Update
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
Expand All @@ -42,6 +38,16 @@ As an alternative to this module
`click-odoo-update <https://github.com/acsone/click-odoo-contrib>`__ can
also be integrated in your non-Odoo maintenance tools instead.

This module gives Odoo the ability to upgrade a module automatically
when its version number is bumped, similar to how Odoo.sh works. This
feature is very useful in Docker deployments (doubly-so for
docker-in-cloud), where upgrading modules via the command-line can be
difficult or impossible.

In particular, this module is handy when adding new fields to
``res.users`` or ``res.company``, which will often cause the Odoo UI to
break until the module is upgraded.

**Table of contents**

.. contents::
Expand All @@ -61,6 +67,12 @@ In addition to the above pattern, .po files corresponding to languages
that are not installed in the Odoo database are ignored when computing
checksums.

This module must be added to the ``server_wide_modules`` in your Odoo
configuration. You must also specify a ``db_name`` in the config, e.g.,
``db_name = FirstDB,AnotherDB`` - the module **will not work** in
multi-DB mode. You must also specify ``module_auto_update = True`` in
the config, or start the server with ``odoo --update auto-update``.

Usage
=====

Expand Down Expand Up @@ -88,6 +100,16 @@ following in an Odoo shell session:

env['ir.module.module'].upgrade_changed_checksum()

Increment the ``version`` key in your modules' ``__manifest__.py``, then
restart Odoo.

Known issues / Roadmap
======================

- Load ``modules_auto_update_disabled`` from config; default to
[``studio_customization``].
- Support config ``module_auto_update_type`` = ``checksum``.

Bug Tracker
===========

Expand Down Expand Up @@ -118,8 +140,10 @@ Contributors
- Stéphane Bidoul <stephane.bidoul@acsone.eu> (https://acsone.eu)
- Eric Antones <eantones@nuobit.com>
- Manuel Engel <manuel.engel@initos.com>
- PyTech SRL info@pytech.it
- Ooops404 info@ooops404.com
- PyTech SRL <info@pytech.it>
- Ooops404 <info@ooops404.com>
- Ryan Cole <hello@ryanc.me>
- Adam Heinz <adam.heinz@metricwise.com> (https://metricwise.com)

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions module_auto_update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import models
from . import wizard
from .hooks import uninstall_hook
from .post_load import post_load
1 change: 1 addition & 0 deletions module_auto_update/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
"wizard/module_auto_update_views.xml",
],
"development_status": "Production/Stable",
"post_load": "post_load",
}
3 changes: 3 additions & 0 deletions module_auto_update/patches/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from .load_modules import patch_load_modules
86 changes: 86 additions & 0 deletions module_auto_update/patches/load_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

import logging
import os

from odoo import SUPERUSER_ID, api, modules
from odoo.modules import loading
from odoo.modules.loading import load_module_graph
from odoo.tools import config, parse_version

_load_modules = loading.load_modules
_logger = logging.getLogger(__name__)


def load_modules(registry, force_demo=False, status=None, update_module=False):
# load_modules is a good spot to hook, because modules __init__.py are called
# before this, but the registry is not yet fully loaded (so we avoid some weird
# issues with .mapped() and computed fields).
modules_to_update = get_updateable_modules(registry)
if modules_to_update:
config["update"].update({k: 1 for k in modules_to_update})
update_module = modules_to_update or update_module
return _load_modules(
registry, force_demo=force_demo, status=status, update_module=update_module
)


def get_updateable_modules(registry):
with registry.cursor() as cr:
if not modules.db.is_initialized(cr):
_logger.debug("Skipping auto-update; database not initialized")
return False

if config["init"]:
_logger.debug("Skipping auto-update; install requested")
return False

_logger.debug("Checking database `%s` for modules to auto-update", cr.dbname)

# set up minimal environment
graph = modules.graph.Graph()
graph.add_module(cr, "base", [])
env = api.Environment(cr, SUPERUSER_ID, {})
load_module_graph(
env, graph, None, perform_checks=False, report=None, models_to_check=None
)
registry.setup_models(cr)

# fetch installed modules
Module = env["ir.module.module"]
Module.update_list()

# TODO Load from config: modules_auto_update_disabled
no_update = ["studio_customization"]

# check for modules that need upgrading (and log them)
to_update = []
for module in Module.search(
[
("state", "=", "installed"),
("name", "not in", no_update),
],
):
# Per odoo/addons/base/models/ir_module.py
# installed_version refers the latest version (the one on disk)
# latest_version refers the installed version (the one in database)
if parse_version(module["latest_version"]) < parse_version(
module["installed_version"]
):
_logger.info(
f"Auto-upgrading module {module['name']} "
f"({module['latest_version']} -> {module['installed_version']})"
)
to_update.append(module["name"])

return to_update


def patch_load_modules():
if config.get(
"module_auto_update",
os.environ.get("ODOO_MODULE_AUTO_UPDATE"),
):
loading.load_modules = load_modules
modules.load_modules = load_modules
_logger.info("patched load_modules")
7 changes: 7 additions & 0 deletions module_auto_update/post_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from .patches import patch_load_modules


def post_load():
patch_load_modules()
5 changes: 5 additions & 0 deletions module_auto_update/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ This module supports the following system parameters:
In addition to the above pattern, .po files corresponding to languages
that are not installed in the Odoo database are ignored when computing
checksums.

This module must be added to the `server_wide_modules` in your Odoo configuration. You
must also specify a `db_name` in the config, e.g., `db_name = FirstDB,AnotherDB` - the
module **will not work** in multi-DB mode. You must also specify `module_auto_update = True`
in the config, or start the server with `odoo --update auto-update`.
6 changes: 4 additions & 2 deletions module_auto_update/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
- Stéphane Bidoul \<<stephane.bidoul@acsone.eu>\> (<https://acsone.eu>)
- Eric Antones \<<eantones@nuobit.com>\>
- Manuel Engel \<<manuel.engel@initos.com>\>
- PyTech SRL <info@pytech.it>
- Ooops404 <info@ooops404.com>
- PyTech SRL \<<info@pytech.it>\>
- Ooops404 \<<info@ooops404.com>\>
- Ryan Cole \<<hello@ryanc.me>\>
- Adam Heinz \<<adam.heinz@metricwise.com>\> (<https://metricwise.com>)
8 changes: 8 additions & 0 deletions module_auto_update/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ upgrade.
As an alternative to this module
[click-odoo-update](https://github.com/acsone/click-odoo-contrib) can
also be integrated in your non-Odoo maintenance tools instead.

This module gives Odoo the ability to upgrade a module automatically when its version
number is bumped, similar to how Odoo.sh works. This feature is very useful in Docker
deployments (doubly-so for docker-in-cloud), where upgrading modules via the
command-line can be difficult or impossible.

In particular, this module is handy when adding new fields to `res.users` or
`res.company`, which will often cause the Odoo UI to break until the module is upgraded.
2 changes: 2 additions & 0 deletions module_auto_update/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Load `modules_auto_update_disabled` from config; default to [`studio_customization`].
- Support config `module_auto_update_type` = `checksum`.
2 changes: 2 additions & 0 deletions module_auto_update/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ following in an Odoo shell session:
``` python
env['ir.module.module'].upgrade_changed_checksum()
```

Increment the `version` key in your modules' `__manifest__.py`, then restart Odoo.
Loading
Loading