[IMP] web: allow read_progress_bar to group by m2m fields
The value returned by the search_read in read_progress_bar when passing a m2m field is a list of ids, which then read_progress_bar tries to use in a dictionary, list is not a hashable type thus it crashes. With this commit we convert the group_by_value from list to tuple, which is hashable, if we're dealing with a many2many field. task-2508608 Part-of: odoo/odoo#74985
This commit is contained in:
@@ -213,6 +213,9 @@ class Base(models.AbstractModel):
|
||||
group_by_value, format=DISPLAY_DATE_FORMATS[group_by_modifier],
|
||||
locale=locale)
|
||||
|
||||
if field_type == 'many2many' and isinstance(group_by_value, list):
|
||||
group_by_value = str(tuple(group_by_value)) or False
|
||||
|
||||
record_values[group_by] = group_by_value
|
||||
record_values['__count'] = 1
|
||||
|
||||
|
||||
@@ -11,6 +11,20 @@ class TestReadProgressBar(common.TransactionCase):
|
||||
super(TestReadProgressBar, self).setUp()
|
||||
self.Model = self.env['res.partner']
|
||||
|
||||
def test_read_progress_bar_m2m(self):
|
||||
""" Test that read_progress_bar works with m2m field grouping """
|
||||
progressbar = {
|
||||
'field': 'type',
|
||||
'colors': {
|
||||
'contact': 'success', 'private': 'danger', 'other': 'muted',
|
||||
}
|
||||
}
|
||||
result = self.env['res.partner'].read_progress_bar([], 'category_id', progressbar)
|
||||
# check that it works when grouping by m2m field
|
||||
self.assertTrue(result)
|
||||
# check the null group
|
||||
self.assertIn('False', result)
|
||||
|
||||
def test_week_grouping(self):
|
||||
"""The labels associated to each record in read_progress_bar should match
|
||||
the ones from read_group, even in edge cases like en_US locale on sundays
|
||||
|
||||
Reference in New Issue
Block a user