diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-11-08 12:42:55 +0100 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-11-08 17:19:28 +0100 |
| commit | c13c9e0b5c6ff8a8ae030ff2467d4675fb6197b8 (patch) | |
| tree | 5d20f76d79d417c35fbfb03e02d35a5320d09be8 /addons/web/static | |
| parent | 9f0bc83788d0a137f8b2c02aaa2cb8ece6628b85 (diff) | |
[FIX] web: invalid domain in DomainSelector
A domain could contain the key `parent` (in an embedded subview), like:
domain="[('display_name', '=', parent.display_name)]")
This is currently not handled by the DomainSelector.
This will probably be handled in a future version but for this stable version,
this case that triggered an error is now catched and an error message is
displayed in the widget.
This was causing a traceback when opening a domain with `parent` in the edition
of a subview with Studio.
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/widgets/domain_selector.js | 21 | ||||
| -rw-r--r-- | addons/web/static/tests/widgets/domain_selector_tests.js | 19 |
2 files changed, 39 insertions, 1 deletions
diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js index 782128994db..0619cf613c6 100644 --- a/addons/web/static/src/js/widgets/domain_selector.js +++ b/addons/web/static/src/js/widgets/domain_selector.js @@ -179,7 +179,16 @@ var DomainTree = DomainNode.extend({ */ init: function (parent, model, domain, options) { this._super.apply(this, arguments); - this._initialize(Domain.prototype.stringToArray(domain)); + try { + domain = Domain.prototype.stringToArray(domain); + } catch (err) { + // TODO: domain could contain `parent` for example, which is + // currently not handled by the DomainSelector + this.invalidDomain = true; + this.children = []; + return; + } + this._initialize(domain); }, /** * @see DomainNode.start @@ -443,6 +452,16 @@ var DomainSelector = DomainTree.extend({ domain_changed: "_onDomainChange", }), + start: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + if (self.invalidDomain) { + var msg = _t("This domain is not supported."); + self.$el.html(msg); + } + }); + }, + //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- diff --git a/addons/web/static/tests/widgets/domain_selector_tests.js b/addons/web/static/tests/widgets/domain_selector_tests.js index 55ddc971642..aca017e831c 100644 --- a/addons/web/static/tests/widgets/domain_selector_tests.js +++ b/addons/web/static/tests/widgets/domain_selector_tests.js @@ -194,6 +194,25 @@ QUnit.module('DomainSelector', { domainSelector.destroy(); }); + + QUnit.test("editing a domain with `parent` key", function (assert) { + assert.expect(1); + + var $target = $("#qunit-fixture"); + + // Create the domain selector and its mock environment + var domainSelector = new DomainSelector(null, "product", "[['name','=',parent.foo]]", { + debugMode: true, + readonly: false, + }); + testUtils.addMockEnvironment(domainSelector, {data: this.data}); + domainSelector.appendTo($target); + + assert.strictEqual(domainSelector.$el.text(), "This domain is not supported.", + "an error message should be displayed because of the `parent` key"); + + domainSelector.destroy(); + }); }); }); }); |
