[FIX] web: allow to build a domain from a number

Some views were trying to make fields invisible thanks to
`attrs="{'invisible': 1}"`.
This is not supposed to be valid as an attrs value is supposed to be
a domain and not a number. To make the fields always invisible, use
the "invisible" *attribute*. This also allows the client to make the
fields invisible without any domain computation.

However, to keep supporting those kind of attrs and to be more generic,
the Domain class is adapted by this commit to consider numeric domains
to be valid (numbers different than 0 are considered "true" domains and
0 is considered a "false" domain).
This commit is contained in:
qsm-odoo
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent 6da2e588b1
commit 825cd69dc0
2 changed files with 11 additions and 3 deletions
+4 -3
View File
@@ -19,15 +19,16 @@ var Domain = collections.Tree.extend({
* * a boolean where the "true" domain match all records and the
* "false" domain does not match any records.
* * undefined, considered as the false boolean.
* * a number, considered as true except 0 considered as false.
* @param {Object} [evalContext] - in case the given domain is a string, an
* evaluation context might be needed
*/
init: function (domain, evalContext) {
this._super.apply(this, arguments);
if (domain === true || domain === false || domain === undefined) {
this._data = domain || false;
} else {
if (_.isArray(domain) || _.isString(domain)) {
this._parse(this.normalizeArray(_.clone(this.stringToArray(domain, evalContext))));
} else {
this._data = !!domain;
}
},
@@ -51,5 +51,12 @@ QUnit.module('core', {}, function () {
assert.ok(new Domain(['!', ['a', '=', 3]]).compute(fields));
assert.ok(new Domain(['!', ['group_method','=','count']]).compute(fields));
});
QUnit.test("domains initialized with a number", function (assert) {
assert.expect(2);
assert.ok(new Domain(1).compute({}));
assert.notOk(new Domain(0).compute({}));
});
});
});