From 0c9e59196502fbdb53d434b9d59e6f3a7593e809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Mon, 24 Apr 2023 08:28:09 +0000 Subject: [PATCH] [FIX] core: read_group same relational grouping Before 916c9c46f58f27c68c5558a2a57fdca43a89fe89, we could groupby several times on the same relational field with `read_group` Example: `read_group(..., groupby=['product_id', 'product_id'], ...)`. Now, it produces a traceback: File "/data/build/odoo/odoo/models.py", line 2583, in read_group self._read_group_format_result(rows_dict, lazy_groupby) File "/data/build/odoo/odoo/models.py", line 2396, in _read_group_format_result ids = [row[group].id for row in rows_dict if row[group]] File "/data/build/odoo/odoo/models.py", line 2396, in ids = [row[group].id for row in rows_dict if row[group]] AttributeError: 'tuple' object has no attribute 'id' It is because `_read_group_format_result` try to convert the record into tuple (id, display_name) twice (one for each groupby). Fix this issue introduced by the refactor of `_read_group`. Part-of: odoo/odoo#119459 --- odoo/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index 3a7c5fb71b6..a11463dbda9 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -2393,7 +2393,7 @@ class BaseModel(metaclass=MetaModel): field = self._fields[field_name] if field.type in ('many2one', 'many2many') or field_name == 'id': - ids = [row[group].id for row in rows_dict if row[group]] + ids = [row[group].id for row in rows_dict if row[group] and isinstance(row[group], BaseModel)] m2x_records = self.env[field.comodel_name].browse(ids) name_get_dict = dict(m2x_records.sudo().name_get()) @@ -2406,7 +2406,7 @@ class BaseModel(metaclass=MetaModel): for row in rows_dict: value = row[group] - if field.type in ('many2one', 'many2many'): + if field.type in ('many2one', 'many2many') and isinstance(value, BaseModel): value = value.id row[group] = (value, name_get_dict[value]) if value else value