2026-03-10 03:59:35 -04:00
|
|
|
#!/usr/bin/env python3
|
2026-03-11 23:15:07 -04:00
|
|
|
# © 2021-2026 TechnoLibre (http://www.technolibre.ca)
|
2026-03-10 03:59:35 -04:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
VERSION_DATA_FILE = os.path.join("conf", "supported_version_erplibre.json")
|
|
|
|
|
INSTALLED_ODOO_VERSION_FILE = os.path.join(
|
|
|
|
|
".repo", "installed_odoo_version.txt"
|
|
|
|
|
)
|
|
|
|
|
ODOO_VERSION_FILE = ".odoo-version"
|
|
|
|
|
|
|
|
|
|
|
2026-03-10 04:05:04 -04:00
|
|
|
def get_odoo_version() -> tuple[list[dict], list[str], str | None]:
|
2026-03-10 03:59:35 -04:00
|
|
|
"""
|
|
|
|
|
Read version configuration and return sorted versions,
|
|
|
|
|
installed versions, and current version.
|
|
|
|
|
"""
|
|
|
|
|
with open(VERSION_DATA_FILE) as txt:
|
|
|
|
|
data_version = json.load(txt)
|
|
|
|
|
|
|
|
|
|
if not data_version:
|
|
|
|
|
raise Exception(
|
|
|
|
|
"Internal error, no Odoo version is supported,"
|
|
|
|
|
f" please validate file '{VERSION_DATA_FILE}'"
|
|
|
|
|
)
|
|
|
|
|
version_entries = []
|
|
|
|
|
for key, value in data_version.items():
|
|
|
|
|
version_entries.append(value)
|
|
|
|
|
value["erplibre_version"] = key
|
|
|
|
|
|
|
|
|
|
installed_versions = []
|
|
|
|
|
if os.path.exists(INSTALLED_ODOO_VERSION_FILE):
|
|
|
|
|
with open(INSTALLED_ODOO_VERSION_FILE) as txt:
|
|
|
|
|
installed_versions = sorted(txt.read().splitlines())
|
|
|
|
|
|
|
|
|
|
odoo_installed_version = None
|
|
|
|
|
if os.path.exists(ODOO_VERSION_FILE):
|
|
|
|
|
with open(ODOO_VERSION_FILE) as txt:
|
|
|
|
|
odoo_installed_version = f"odoo{txt.read().strip()}"
|
|
|
|
|
|
2026-03-10 04:05:04 -04:00
|
|
|
versions = sorted(version_entries, key=lambda k: k.get("erplibre_version"))
|
2026-03-10 03:59:35 -04:00
|
|
|
|
|
|
|
|
return versions, installed_versions, odoo_installed_version
|