[FIX] web: FieldDomain: reset field with a new domain

Before this rev., there was a crash when a FieldDomain was reset
with a new domain (e.g. coming from an onchange). For instance, it
crashed in Email Marketing > create new Mass Mailing > select
mailing lists. Introduced by 68332a01.

opw-1882850
This commit is contained in:
Aaron Bohy
2018-09-07 08:37:45 +02:00
parent 737ca0eb42
commit a51a5b70d3
2 changed files with 38 additions and 1 deletions
@@ -491,7 +491,7 @@ var DomainSelector = DomainTree.extend({
}
var parsedDomain = this._parseDomain(domain);
if (parsedDomain) {
return this._redraw(domain);
return this._redraw(parsedDomain);
}
},
@@ -4521,6 +4521,43 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('domain field can be reset with a new domain (from onchange)', function (assert) {
assert.expect(2);
this.data.partner.records[0].foo = '[]';
this.data.partner.onchanges = {
display_name: function (obj) {
obj.foo = '[["id", "=", 1]]';
},
};
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form>' +
'<field name="display_name"/>' +
'<field name="foo" widget="domain" options="{\'model\': \'partner\'}"/>' +
'</form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
assert.equal(form.$('.o_domain_show_selection_button').text().trim(), '5 record(s)',
"the domain being empty, there should be 5 records");
// update display_name to trigger the onchange and reset foo
form.$('.o_field_widget[name=display_name]').val('new value').trigger('input');
assert.equal(form.$('.o_domain_show_selection_button').text().trim(), '1 record(s)',
"the domain has changed, there should be only 1 record");
form.destroy();
});
QUnit.test('domain field: handle false domain as []', function (assert) {
assert.expect(3);