Skip to content

Commit 2029cc9

Browse files
committed
[FIX] add compatibility with Odoo >=17
At last, you can enjoy this lib in modern Odoo instances!
1 parent 4a2ee9e commit 2029cc9

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

odooshow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.6.0"
1+
__version__ = "0.6.1"
22
__author__ = "David Vidal"
33
__email__ = "[email protected]"
44
__doc__ = """A library to give goggles when diving into the Odoo Shell"""

odooshow/odooshow.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2022 David Vidal
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3+
from odoo.release import major_version
34
import warnings
45

56
from rich import box
@@ -311,7 +312,7 @@ def _show(
311312
name="",
312313
fields=None,
313314
view_id=None,
314-
view_type="tree",
315+
view_type="list",
315316
groupby=None,
316317
partials=None,
317318
**extra,
@@ -322,7 +323,7 @@ def _show(
322323
:param str name: Table name
323324
:param list fields: List of fields to render as columns, defaults to None
324325
:param int view_id: Default view id, defaults to None
325-
:param str view_type: View type to take default fields form, defaults to "tree"
326+
:param str view_type: View type to take default fields form, defaults to "list"
326327
:param str groupby: Field name to group by records, defaults to None
327328
:param bool partials: Show operator partials when grouping, defaults to None
328329
:return rich.table: Rich Table Object
@@ -342,9 +343,16 @@ def _show(
342343
)
343344
# Compatibility with OdooRPC to access the object fields properties
344345
records_obj = records.env[records._name]
346+
# Ensure compatibility
347+
if major_version < "18.0" and view_type == "list":
348+
view_type = "tree"
349+
if not fields and major_version >= "16.0":
350+
fields = records_obj.get_view(
351+
view_id=view_id, view_type=view_type
352+
)["models"][records_obj._name]
345353
if fields:
346354
fields = self._get_field_attributes(fields, records_obj)
347-
else:
355+
elif major_version < "16.0":
348356
# Get fields from default tree view
349357
# Since v16 the method is deprecated. For the moment just silence warnings
350358
with warnings.catch_warnings():
@@ -383,7 +391,7 @@ def show(
383391
records,
384392
fields=None,
385393
view_id=None,
386-
view_type="tree",
394+
view_type="list",
387395
groupby=None,
388396
raw=None,
389397
partials=None,
@@ -394,7 +402,7 @@ def show(
394402
:param recordset records: Any Odoo recordset
395403
:param list fields: List of fields to render as columns, defaults to None
396404
:param int view_id: Default view id, defaults to None
397-
:param str view_type: View type to take default fields form, defaults to "tree"
405+
:param str view_type: View type to take default fields form, defaults to "list"
398406
:param str groupby: Field name to group by records, defaults to None
399407
:param boolean raw: Return a `rich.table` object instead of render, defaults to None
400408
:param boolean partials: Show operator partials when grouping, defaults to None

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "odooshow"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
description = "Make use of rich power tools to have nice formatted data in Odoo shells"
55
authors = ["David Vidal <[email protected]>"]
66

0 commit comments

Comments
 (0)