From 68332a0177990020f11b94317a6d3a81ff906d69 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 17 Aug 2018 13:39:29 +0200 Subject: [FIX] web: fix evaluation context of the domain selector The domain was instantiated without being given any evaluation context. As a result, the uid variable was not defined, crashing the js if present in a user-defined filter. opw 1866852 --- .../web/static/tests/fields/basic_fields_tests.js | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index f2ab670f097..4dd595cbfa0 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -4345,6 +4345,33 @@ QUnit.module('basic_fields', { QUnit.module('FieldDomain'); + QUnit.test('The domain editor should not crash the view when given a dynamic filter', function (assert) { + //dynamic filters (containing variables, such as uid, parent or today) + //are not handled by the domain editor, but it shouldn't crash the view + assert.expect(1); + + this.data.partner.records[0].foo = '[["int_field", "=", uid]]'; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '
' + + '' + + '' + + '', + res_id: 1, + session: { + user_context: {uid: 14}, + }, + }); + + assert.strictEqual(form.$('.o_read_mode').text(), "This domain is not supported.", + "The widget should not crash the view, but gracefully admit its failure."); + form.destroy(); + }); + QUnit.test('basic domain field usage is ok', function (assert) { assert.expect(6); -- cgit v1.2.3 From a51a5b70d3c78b65d32a9fa576dffa3d8a2af666 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 7 Sep 2018 08:26:12 +0200 Subject: [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 --- .../web/static/tests/fields/basic_fields_tests.js | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 4dd595cbfa0..fade0282f69 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -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: + '
' + + '' + + '' + + '', + 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); -- cgit v1.2.3