Skip to content

Commit

Permalink
Merge pull request #124 from acsone/version_info
Browse files Browse the repository at this point in the history
Use version_info instead of parse_version
  • Loading branch information
sbidoul authored Oct 18, 2022
2 parents f3298b0 + bdf53dc commit 1c15e02
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
9 changes: 2 additions & 7 deletions click_odoo_contrib/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .update import _save_installed_checksums

_logger = logging.getLogger(__name__)
_odoo_version = odoo.tools.parse_version(odoo.release.version)


EXCLUDE_PATTERNS = ("*.pyc", "*.pyo")
Expand Down Expand Up @@ -48,7 +47,7 @@ def _db_storage(self):
# make sure attachments created during db initialization
# are stored in database, so we get something consistent
# when recreating the db by copying the cached template
if _odoo_version >= odoo.tools.parse_version("12"):
if odoo.release.version_info >= (12, 0):
from odoo.addons.base.models.ir_attachment import IrAttachment
else:
from odoo.addons.base.ir.ir_attachment import IrAttachment
Expand All @@ -65,11 +64,7 @@ def odoo_createdb(dbname, demo, module_names, force_db_storage):
odoo.service.db._create_empty_database(dbname)
odoo.tools.config["init"] = dict.fromkeys(module_names, 1)
odoo.tools.config["without_demo"] = not demo
if _odoo_version < odoo.tools.parse_version("10"):
Registry = odoo.modules.registry.RegistryManager
else:
Registry = odoo.modules.registry.Registry
Registry.new(dbname, force_demo=demo, update_module=True)
odoo.modules.registry.Registry.new(dbname, force_demo=demo, update_module=True)
_logger.info(
click.style(
"Created new Odoo database {dbname}.".format(**locals()), fg="green"
Expand Down
6 changes: 1 addition & 5 deletions click_odoo_contrib/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,7 @@ def _update_db_nolock(
return
if i18n_overwrite:
odoo.tools.config["overwrite_existing_translations"] = True
if odoo.tools.parse_version(odoo.release.version) < odoo.tools.parse_version("10"):
Registry = odoo.modules.registry.RegistryManager
else:
Registry = odoo.modules.registry.Registry
Registry.new(database, update_module=True)
odoo.modules.registry.Registry.new(database, update_module=True)
if watcher and watcher.aborted:
# If you get here, the updating session has been terminated and it
# somehow has recovered by opening a new cursor and continuing;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import sys
import textwrap
from datetime import datetime, timedelta
from unittest import mock

import click_odoo
import mock
import pytest
from click.testing import CliRunner

Expand Down
4 changes: 2 additions & 2 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_manifest_expand_dependencies():
assert "base_import" in res
assert "base" in res # obviously
assert "web" in res # base_import depends on web
if odoo.tools.parse_version(odoo.release.version) < odoo.tools.parse_version("12"):
if odoo.release.version_info < (12, 0):
assert "auth_crypt" not in res
else:
assert "iap" not in res # iap is auto_install
Expand All @@ -42,7 +42,7 @@ def test_manifest_expand_dependencies_auto_install():
res = manifest.expand_dependencies(["auth_signup"], include_auto_install=True)
assert "auth_signup" in res
assert "base" in res # obviously
if odoo.tools.parse_version(odoo.release.version) < odoo.tools.parse_version("12"):
if odoo.release.version_info < (12, 0):
assert "auth_crypt" in res # auth_crypt is autoinstall
else:
assert "iap" in res # iap is auto_install
Expand Down
2 changes: 1 addition & 1 deletion tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_update(odoodb):
assert "base" not in checksums # because ignore_Core_addons=True
with pytest.raises(subprocess.CalledProcessError):
_update_one(odoodb, "v7")
if odoo.tools.parse_version(odoo.release.version) >= odoo.tools.parse_version("12"):
if odoo.release.version_info >= (12, 0):
# Odoo >= 12 does -u in a transaction
_check_expected(odoodb, "v6")

Expand Down

0 comments on commit 1c15e02

Please sign in to comment.