[FIX] web: mock name search actually evaluates the domain

Before this commit, the _mockNameSearch method of the mock server was
computing by hand the first element of the domain.  This was adhoc and
wrong (for example, the '==' operator).  Also, we actually have a method
designed to just return the records matching a given domain.
This commit is contained in:
Géry Debongnie
2017-07-18 14:45:22 +02:00
parent 5f8dea490a
commit f7dd085e80
2 changed files with 5 additions and 21 deletions
@@ -995,14 +995,16 @@ QUnit.module('relational_fields', {
assert.deepEqual(
args.kwargs.context,
{hey: "ho", hello: "world", test: "yop"},
'the field attr context should have been used for the '
+ 'RPC (evaluated and merged with the session one)');
'the field attr context should have been used for the ' +
'RPC (evaluated and merged with the session one)');
return $.when([]);
}
if (args.method === 'name_search' && args.model === 'partner') {
assert.deepEqual(args.kwargs.args, [['id', 'in', [12]]],
'the field attr domain should have been used for the RPC (and evaluated)');
assert.deepEqual(args.kwargs.context, {hey: 'ho', timmy: [[6, false, [12]]]},
'the field attr context should have been used for the RPC (and evaluated)');
return $.when([]);
}
return this._super.apply(this, arguments);
},
+1 -19
View File
@@ -465,25 +465,7 @@ var MockServer = Class.extend({
_mockNameSearch: function (model, args, _kwargs) {
var str = args && typeof args[0] === 'string' ? args[0] : _kwargs.name;
var domain = (args && args[1]) || _kwargs.args || [];
var dom = domain[0];
var records = this.data[model].records;
if (dom) {
records = _.filter(records, function (record) {
var value = record[dom[0]];
if (value instanceof Array) {
value = value[0];
}
if (dom[1] === 'not in') {
return !_.contains(dom[2], value);
} else if (dom[1] === 'in') {
return _.contains(dom[2], value);
} else if (dom[1] === '==') {
return dom[2] == value;
} else if (dom[1] === '!=') {
return dom[2] != value;
}
});
}
var records = this._getRecords(model, domain);
if (str.length) {
records = _.filter(records, function (record) {
return record.display_name.indexOf(str) !== -1;