From 64dd7d54439277a50441ffcef0f1dbe0b0640e1f Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 22 Mar 2017 08:48:36 +0100 Subject: [PATCH] [IMP] web: rpc: more permissive API for read_group This rev. allows to specify some kwargs of read_group directly in an Object given to kwargs(), instead of explicitly specify them using the corresponding method (e.g. to specify the context in the kwargs instead of by calling .withContext(). --- addons/web/static/src/js/core/rpc.js | 2 +- addons/web/static/test/core/rpc_tests.js | 32 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/core/rpc.js b/addons/web/static/src/js/core/rpc.js index a6d314f35a2..bb1b6740048 100644 --- a/addons/web/static/src/js/core/rpc.js +++ b/addons/web/static/src/js/core/rpc.js @@ -264,7 +264,7 @@ var ReadGroupRPCBuilder = SearchRPCBuilder.extend({ * @returns {Object} */ _getParams: function () { - var kwargs = _.extend({}, this._kwargs, { + var kwargs = _.defaults({}, this._kwargs, { context: this._context || {}, domain: this._domain || [], fields: this._fields, diff --git a/addons/web/static/test/core/rpc_tests.js b/addons/web/static/test/core/rpc_tests.js index 216043630d4..053cace7ce6 100644 --- a/addons/web/static/test/core/rpc_tests.js +++ b/addons/web/static/test/core/rpc_tests.js @@ -208,6 +208,38 @@ QUnit.module('core', {}, function () { .exec(); }); + QUnit.test('read_group with kwargs', function (assert) { + assert.expect(2); + var query = createQuery({ + model: 'partner', + method: 'read_group', + mockRPC: function (route, args) { + assert.deepEqual(args, { + args: [], + kwargs: { + context: {abc: 'def'}, + domain: ['a', '=', 1], + fields: ['name'], + groupby: ['product_id'], + lazy: true, + orderby: false, + }, + method: 'read_group', + model: 'partner', + }, "should have correct args"); + assert.equal(route, '/web/dataset/call_kw/partner/read_group', + "should call correct route"); + }, + }); + query + .withDomain(['a', '=', 1]) + .withFields(['name']) + .groupBy(['product_id']) + .kwargs({context: {abc: 'def'}}) + .lazy(true) + .exec(); + }); + QUnit.test('search_read with no domain, nor fields', function (assert) { assert.expect(2); createQuery({