diff --git a/addons/web/models/models.py b/addons/web/models/models.py index b1a5908fdf0..b68f0b52e10 100644 --- a/addons/web/models/models.py +++ b/addons/web/models/models.py @@ -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 diff --git a/addons/web/tests/test_read_progress_bar.py b/addons/web/tests/test_read_progress_bar.py index c4d1a5b0e75..2c265d9797e 100644 --- a/addons/web/tests/test_read_progress_bar.py +++ b/addons/web/tests/test_read_progress_bar.py @@ -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