1 openerp.testing.section('data.model.group_by', {
3 dependencies: ['web.data'],
6 bar: 3, bar_count: 5, __context: {}, __domain: [['bar', '=', 3]],
8 bar: 5, bar_count: 3, __context: {}, __domain: [['bar', '=', 5]],
10 bar: 8, bar_count: 0, __context: {}, __domain: [['bar', '=', 8]],
12 test('basic', {asserts: 7}, function (instance, $fix, mock) {
13 var m = new instance.web.Model('foo');
14 mock('foo:read_group', function (args, kwargs) {
15 deepEqual(kwargs.fields, ['bar'],
16 "should read grouping field");
17 deepEqual(kwargs.groupby, ['bar'],
18 "should have single grouping field");
21 mock('/web/dataset/search_read', function (args) {
22 deepEqual(args.params.domain, [['bar', '=', 3]],
23 "should have domain matching that of group_by result");
33 return m.query().group_by('bar')
34 .then(function (groups) {
35 ok(groups, "should have data");
36 equal(groups.length, 3, "should have three results");
37 var first = groups[0];
38 ok(first.attributes.has_children, "should have children");
39 return first.query().all();
40 }).done(function (first) {
41 equal(first.length, 5, "should have 5 records");
44 test('noleaf', {asserts: 5}, function (instance, $fix, mock) {
45 var m = new instance.web.Model('foo', {group_by_no_leaf: true});
46 mock('foo:read_group', function (args, kwargs) {
47 deepEqual(kwargs.fields, ['bar'],
48 "should read grouping field");
49 deepEqual(kwargs.groupby, ['bar'],
50 "should have single grouping field");
54 return m.query().group_by('bar')
55 .then(function (groups) {
56 ok(groups, "should have data");
57 equal(groups.length, 3, "should have three results");
58 ok(!groups[0].attributes.has_children,
59 "should not have children because no_leaf");
62 test('nogroup', {rpc: false}, function (instance, $f, mock) {
63 var m = new instance.web.Model('foo');
64 strictEqual(m.query().group_by(), null, "should not group");
66 test('empty.noleaf', {asserts: 1}, function (instance, $f, mock) {
67 var m = new instance.web.Model('foo', {group_by_no_leaf: true});
68 mock('foo:read_group', function (args, kwargs) {
69 return [{__context: [], __domain: []}];
71 return m.query().group_by().done(function (groups) {
72 strictEqual(groups.length, 1,
73 "should generate a single fake-ish group");