Skip to content

Commit df2ad23

Browse files
committed
[IMP] module_auto_update: Create command to execute auto_upgrade directly without shell
1 parent 9aa256d commit df2ad23

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed

module_auto_update/README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ in an Odoo shell session:
7777
7878
env['ir.module.module'].upgrade_changed_checksum()
7979
80+
For integration in toolchains the upgrade mechanism can also be invoked using the Odoo cli command ``auto_update``. The `--addons-path=` is required as first argument:
81+
82+
.. code-block:: bash
83+
84+
odoo-bin --addons-path=... auto_update -d odoo
85+
# or
86+
odoo-bin --addons-path=... auto_update -c path/to/odoo.cfg
87+
8088
Bug Tracker
8189
===========
8290

module_auto_update/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
22

3-
from . import models
3+
from . import cli, models
44
from .hooks import uninstall_hook

module_auto_update/cli/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# © 2025 initOS GmbH
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from . import auto_update
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# © 2025 initOS GmbH
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
import odoo
5+
from odoo import api
6+
from odoo.cli.shell import Shell
7+
from odoo.tools import config
8+
9+
10+
class ModuleAutoUpgrade(Shell):
11+
"""Run auto upgrade"""
12+
13+
name = "auto_update"
14+
15+
def run(self, args):
16+
self.init(args)
17+
registry = odoo.registry(config["db_name"])
18+
with registry.cursor() as cr:
19+
uid = odoo.SUPERUSER_ID
20+
ctx = (
21+
odoo.api.Environment(cr, uid, {})["res.users"]
22+
.with_context(prefetch_fields=False)
23+
.context_get()
24+
)
25+
26+
env = api.Environment(cr, uid, ctx)
27+
env["ir.module.module"].upgrade_changed_checksum(
28+
overwrite_existing_translations=config[
29+
"overwrite_existing_translations"
30+
],
31+
)
32+
return 0

module_auto_update/readme/USAGE.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ in an Odoo shell session:
2020
.. code-block:: python
2121
2222
env['ir.module.module'].upgrade_changed_checksum()
23+
24+
For integration in toolchains the upgrade mechanism can also be invoked using the Odoo cli command ``auto_update``. The `--addons-path=` is required as first argument:
25+
26+
.. code-block:: bash
27+
28+
odoo-bin --addons-path=... auto_update -d odoo
29+
# or
30+
odoo-bin --addons-path=... auto_update -c path/to/odoo.cfg

module_auto_update/static/description/index.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -419,6 +420,12 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
419420
<pre class="code python literal-block">
420421
<span class="n">env</span><span class="p">[</span><span class="s1">'ir.module.module'</span><span class="p">]</span><span class="o">.</span><span class="n">upgrade_changed_checksum</span><span class="p">()</span>
421422
</pre>
423+
<p>For integration in toolchains the upgrade mechanism can also be invoked using the Odoo cli command <tt class="docutils literal">auto_update</tt>. The <cite>–addons-path=</cite> is required as first argument:</p>
424+
<pre class="code bash literal-block">
425+
odoo-bin<span class="w"> </span>--addons-path<span class="o">=</span>...<span class="w"> </span>auto_update<span class="w"> </span>-d<span class="w"> </span>odoo<span class="w">
426+
</span><span class="c1"># or
427+
</span>odoo-bin<span class="w"> </span>--addons-path<span class="o">=</span>...<span class="w"> </span>auto_update<span class="w"> </span>-c<span class="w"> </span>path/to/odoo.cfg
428+
</pre>
422429
</div>
423430
<div class="section" id="bug-tracker">
424431
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
@@ -453,7 +460,9 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
453460
<div class="section" id="maintainers">
454461
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
455462
<p>This module is maintained by the OCA.</p>
456-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
463+
<a class="reference external image-reference" href="https://odoo-community.org">
464+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
465+
</a>
457466
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
458467
mission is to support the collaborative development of Odoo features and
459468
promote its widespread use.</p>

0 commit comments

Comments
 (0)