From de5a3d93585437aea7a34003108170ce89953499 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 7 Oct 2022 00:29:01 +0200 Subject: [PATCH] [FIX] Compatibility with v16 Since v16 the field_view_get method is officially deprecated. For the moment, we'll just silence warnings. --- odooshow/__init__.py | 2 +- odooshow/odooshow.py | 23 ++++++++++++++++------- pyproject.toml | 2 +- tests/test_odooshow.py | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/odooshow/__init__.py b/odooshow/__init__.py index 82c6eb9..1af7290 100644 --- a/odooshow/__init__.py +++ b/odooshow/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.5.0" +__version__ = "0.5.1" __author__ = "David Vidal" __email__ = "chienandalu@gmail.com" __doc__ = """A library to give goggles when diving into the Odoo Shell""" diff --git a/odooshow/odooshow.py b/odooshow/odooshow.py index 0692733..fe0e903 100644 --- a/odooshow/odooshow.py +++ b/odooshow/odooshow.py @@ -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 @@ -111,14 +113,15 @@ 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 @@ -126,7 +129,10 @@ def _record_url(self, record): 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 "" @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 7b57f39..238c2cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] diff --git a/tests/test_odooshow.py b/tests/test_odooshow.py index d215bb9..42ce32f 100644 --- a/tests/test_odooshow.py +++ b/tests/test_odooshow.py @@ -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"