[FIX] web: WidgetDomain: don't crash on false domain

Before this rev., when the value of a field with widget='domain'
was false, the search_count RPC made to display the number of
records matching the domain crashed, and the widget displayed that
the domain was invalid. This rev. adds a fallback on [] when the
domain is false.
This commit is contained in:
Aaron Bohy
2017-08-29 13:59:49 +02:00
parent c5bf53682e
commit 4f61e7f048
2 changed files with 39 additions and 1 deletions
@@ -2043,7 +2043,7 @@ var BasicModel = AbstractModel.extend({
if (record.data.hasOwnProperty(domainModel)) {
domainModel = record._changes && record._changes[domainModel] || record.data[domainModel];
}
var domainValue = record._changes && record._changes[fieldName] || record.data[fieldName];
var domainValue = record._changes && record._changes[fieldName] || record.data[fieldName] || [];
// avoid rpc if not necessary
var hasChanged = this._saveSpecialDataCache(record, fieldName, {
@@ -3757,6 +3757,44 @@ QUnit.module('basic_fields', {
"field selector popover should contain 'Color index' field");
form.destroy();
});
QUnit.test('domain field: handle false domain as []', function (assert) {
assert.expect(2);
this.data.partner.records[0].foo = false;
this.data.partner.fields.bar.type = "char";
this.data.partner.records[0].bar = "product";
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form>' +
'<sheet>' +
'<group>' +
'<field name="bar"/>' +
'<field name="foo" widget="domain" options="{\'model\': \'bar\'}"/>' +
'</group>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'search_count') {
assert.deepEqual(args.args[0], [], "should send a valid domain");
}
return this._super.apply(this, arguments);
},
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
var $warning = form.$('.o_field_widget[name=foo] .text-warning');
assert.strictEqual($warning.length, 0, "should not display that the domain is invalid");
form.destroy();
});
});
});
});