Skip to content

Commit

Permalink
[FIX] Compatibility with v16
Browse files Browse the repository at this point in the history
Since v16 the field_view_get method is officially deprecated. For the
moment, we'll just silence warnings.
  • Loading branch information
chienandalu committed Oct 6, 2022
1 parent 2c98b01 commit de5a3d9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion odooshow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.0"
__version__ = "0.5.1"
__author__ = "David Vidal"
__email__ = "[email protected]"
__doc__ = """A library to give goggles when diving into the Odoo Shell"""
Expand Down
23 changes: 16 additions & 7 deletions odooshow/odooshow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright 2022 David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import warnings

from rich import box
from rich.console import Console
from rich.table import Table
Expand Down Expand Up @@ -111,22 +113,26 @@ def _record_url(self, record):
"""

if not hasattr(record, "get_base_url"):
base_url = record.env['ir.config_parameter'].sudo().get_param('web.base.url')
base_url = (
record.env["ir.config_parameter"].sudo().get_param("web.base.url")
)
else:
base_url = record.get_base_url()

if base_url:
return (
f"{base_url}"
f"/web#model={record._name}&id={record.id}&view_type=form"
f"{base_url}" f"/web#model={record._name}&id={record.id}&view_type=form"
)
else:
return None

def _relation_value(self, field_values, attrs=None, record=None):
"""Render related records"""
record_values = [
f"[link={self._record_url(r)}]{r.display_name}[/link]" if self._record_url(r) else f"{r.display_name}" for r in field_values
f"[link={self._record_url(r)}]{r.display_name}[/link]"
if self._record_url(r)
else f"{r.display_name}"
for r in field_values
]
return field_values and ", ".join(record_values) or ""

Expand Down Expand Up @@ -295,9 +301,12 @@ def _show(
}
else:
# Get fields from default tree view
fields = records_obj.fields_view_get(view_id=view_id, view_type=view_type)[
"fields"
]
# Since v16 the method is deprecated. For the moment just silence warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fields = records_obj.fields_view_get(
view_id=view_id, view_type=view_type
)["fields"]
# Allways show the record id first
fields = dict({"id": {"type": "integer"}}, **fields)
# Header
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "odooshow"
version = "0.5.0"
version = "0.5.1"
description = "Make use of rich power tools to have nice formatted data in Odoo shells"
authors = ["David Vidal <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_odooshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_version():
# TODO: Add tests. Not easy though as we need to setup a minimum Odoo instance.
assert __version__ == "0.5.0"
assert __version__ == "0.5.1"

0 comments on commit de5a3d9

Please sign in to comment.