diff options
| author | Raphael Collet <rco@odoo.com> | 2017-05-05 16:37:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-05 16:37:11 +0200 |
| commit | 580e78ad375aa3f52f2307c82281268796275aea (patch) | |
| tree | 177a102564e9ae74d08a4730b03a5105d2132ceb /odoo/addons/test_read_group | |
| parent | cd90e83897dbb9cb10e939c95e8e83411ed5f905 (diff) | |
[IMP] models: enable `field.group_expand` on all types of fields (#16833)
The attribute `group_expand` allows to reorder and add empty groups to the
result of `read_group`. Enable this feature for other fields than many2one
fields.
Diffstat (limited to 'odoo/addons/test_read_group')
| -rw-r--r-- | odoo/addons/test_read_group/__init__.py | 1 | ||||
| -rw-r--r-- | odoo/addons/test_read_group/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | odoo/addons/test_read_group/models.py | 10 | ||||
| -rw-r--r-- | odoo/addons/test_read_group/tests/__init__.py | 1 | ||||
| -rw-r--r-- | odoo/addons/test_read_group/tests/test_group_expand.py | 89 |
5 files changed, 102 insertions, 0 deletions
diff --git a/odoo/addons/test_read_group/__init__.py b/odoo/addons/test_read_group/__init__.py index cde864bae21..567548c78f5 100644 --- a/odoo/addons/test_read_group/__init__.py +++ b/odoo/addons/test_read_group/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import models +from . import tests diff --git a/odoo/addons/test_read_group/ir.model.access.csv b/odoo/addons/test_read_group/ir.model.access.csv index 9660fbbc4a2..af7209767df 100644 --- a/odoo/addons/test_read_group/ir.model.access.csv +++ b/odoo/addons/test_read_group/ir.model.access.csv @@ -1,3 +1,4 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" access_test_read_group_on_date,access_test_read_group_on_date,model_test_read_group_on_date,,1,0,0,0 access_test_read_group_aggregate_boolean,access_test_read_group_aggregate_boolean,model_test_read_group_aggregate_boolean,,1,0,0,0 +access_test_read_group_on_selection,access_test_read_group_on_selection,model_test_read_group_on_selection,,1,0,0,0 diff --git a/odoo/addons/test_read_group/models.py b/odoo/addons/test_read_group/models.py index 9867b179d28..db67a964013 100644 --- a/odoo/addons/test_read_group/models.py +++ b/odoo/addons/test_read_group/models.py @@ -16,3 +16,13 @@ class BooleanAggregate(models.Model): bool_and = fields.Boolean(default=False, group_operator='bool_and') bool_or = fields.Boolean(default=False, group_operator='bool_or') bool_array = fields.Boolean(default=False, group_operator='array_agg') + +class GroupOnSelection(models.Model): + _name = 'test_read_group.on_selection' + + state = fields.Selection([('a', "A"), ('b', "B")], group_expand='_expand_states') + value = fields.Integer() + + def _expand_states(self, states, domain, order): + # return all possible states, in order + return [key for key, val in type(self).state.selection] diff --git a/odoo/addons/test_read_group/tests/__init__.py b/odoo/addons/test_read_group/tests/__init__.py index e0cde2af5e1..aef16fccd7a 100644 --- a/odoo/addons/test_read_group/tests/__init__.py +++ b/odoo/addons/test_read_group/tests/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import test_empty +from . import test_group_expand from . import test_group_operator diff --git a/odoo/addons/test_read_group/tests/test_group_expand.py b/odoo/addons/test_read_group/tests/test_group_expand.py new file mode 100644 index 00000000000..69217981abb --- /dev/null +++ b/odoo/addons/test_read_group/tests/test_group_expand.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +from odoo.tests import common + + +class TestGroupOnSelection(common.TransactionCase): + def setUp(self): + super(TestGroupOnSelection, self).setUp() + self.Model = self.env['test_read_group.on_selection'] + + def test_none(self): + self.Model.create({'value': 1}) + self.Model.create({'value': 2}) + self.Model.create({'value': 3}) + + groups = self.Model.read_group([], fields=['state', 'value'], groupby=['state']) + self.assertEqual(groups, [ + { + 'state': 'a', + 'state_count': 0, + 'value': False, + '__domain': [('state', '=', 'a')], + }, + { + 'state': 'b', + 'state_count': 0, + 'value': False, + '__domain': [('state', '=', 'b')], + }, + { + 'state': False, + 'state_count': 3, + 'value': 6, + '__domain': [('state', '=', False)], + }, + ]) + + def test_partial(self): + self.Model.create({'state': 'a', 'value': 1}) + self.Model.create({'state': 'a', 'value': 2}) + self.Model.create({'value': 3}) + + groups = self.Model.read_group([], fields=['state', 'value'], groupby=['state']) + self.assertEqual(groups, [ + { + 'state': 'a', + 'state_count': 2, + 'value': 3, + '__domain': [('state', '=', 'a')], + }, + { + 'state': 'b', + 'state_count': 0, + 'value': False, + '__domain': [('state', '=', 'b')], + }, + { + 'state': False, + 'state_count': 1, + 'value': 3, + '__domain': [('state', '=', False)], + }, + ]) + + def test_full(self): + self.Model.create({'state': 'a', 'value': 1}) + self.Model.create({'state': 'b', 'value': 2}) + self.Model.create({'value': 3}) + + groups = self.Model.read_group([], fields=['state', 'value'], groupby=['state']) + self.assertEqual(groups, [ + { + 'state': 'a', + 'state_count': 1, + 'value': 1, + '__domain': [('state', '=', 'a')], + }, + { + 'state': 'b', + 'state_count': 1, + 'value': 2, + '__domain': [('state', '=', 'b')], + }, + { + 'state': False, + 'state_count': 1, + 'value': 3, + '__domain': [('state', '=', False)], + }, + ]) |
