From 3f8569a05702a8d14f18e8303e2f9418ec65a287 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 22 Mar 2017 14:55:17 +0100 Subject: [PATCH] [FIX] web: send array domains to the server in domain field The `FieldDomain` was sending string domains instead of array domains to the server (by its associated `BasicModel._fetchSpecialDomain` function). The server does not do the conversion string -> array for domains, so the RPC broke everytime. This commit also modifies the `MockServer` so that tests also break when sending string domains. It also improves the way failed rpc are handled. Indeed when an rpc fails, its deferred is rejected with two arguments: the error object, and a JQuery event (that will display the error if not preventDefaulted). The mockRPC didn't pass the second one and thus there was a crash when reaching code that e.g. calls preventDefault on that event. Note: this also removes the stringify/parse of the error object as it is not a correct simulation of a server error object anyway. --- .../static/src/js/views/basic/basic_model.js | 2 +- addons/web/static/test/helpers/mock_server.js | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 023571d19a4..0c2bbd4d23e 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1551,7 +1551,7 @@ var BasicModel = AbstractModel.extend({ var def = $.Deferred(); this._rpc(domainModel, "search_count") - .args([domainValue]) + .args([Domain.prototype.stringToArray(domainValue)]) .withContext(context) .exec() .then(_.identity, function (error, e) { diff --git a/addons/web/static/test/helpers/mock_server.js b/addons/web/static/test/helpers/mock_server.js index f5202fc2eda..8e10b2b9f49 100644 --- a/addons/web/static/test/helpers/mock_server.js +++ b/addons/web/static/test/helpers/mock_server.js @@ -91,7 +91,12 @@ var MockServer = Class.extend({ try { def = this._performRpc(route, args); } catch (error) { - def = $.Deferred().reject(error); + if (logLevel === 1) { + console.warn('Mock: ' + route, error.message); + } else if (logLevel === 2) { + console.warn('%c[rpc] error response:', 'color: blue; font-weight: bold;', error.message); + } + return $.Deferred().reject(error.message, $.Event()); } return def.then(function (result) { var resultString = JSON.stringify(result || false); @@ -101,14 +106,6 @@ var MockServer = Class.extend({ console.log('%c[rpc] response:', 'color: blue; font-weight: bold;', JSON.parse(resultString)); } return JSON.parse(resultString); - }, function (error) { - var errorString = JSON.stringify(error || false); - if (logLevel === 1) { - console.warn('Mock: ' + route, JSON.parse(errorString)); - } else if (logLevel === 2) { - console.warn('%c[rpc] error response:', 'color: blue; font-weight: bold;', JSON.parse(errorString)); - } - return JSON.parse(errorString); }); }, @@ -230,6 +227,10 @@ var MockServer = Class.extend({ * @returns {Object[]} a list of records */ _getRecords: function (model, domain) { + if (!_.isArray(domain)) { + throw new Error("MockServer._getRecords: given domain has to be an array."); + } + var self = this; var records = this.data[model].records;