[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 <listcomp>
    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
This commit is contained in:
Rémy Voet (ryv)
2023-04-24 23:48:53 +02:00
parent 8e1bc74a67
commit 0c9e591965
+2 -2
View File
@@ -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