diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-04-15 12:41:26 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-04-15 12:41:26 +0000 |
| commit | 7bf25cc333b0a3afc7e0a67f76f019407dba7e12 (patch) | |
| tree | 52740b79fc85915e6467955e9a99a6d75d473403 /addons/web/static | |
| parent | 6a57ad66b8374966ba7011e34cec20f6344f4f6d (diff) | |
[FIX] web: search view handles JSON parsable domains
Before this commit, a domain that had been written in order to be
JSON parsable, would trigger a JS crash when activated in the UI
It happens when adding custom filters through the edition of the search view with studio
This was because, Odoo developers write, in the XML of a search view
domains python style: `[('field', '=', 'value')]`
When parsing the view in JS, this doesn't get altered by `xml_to_json`
Then, the search view code evaluates it python style
This commit considers that behavior fortunate, but not really clear or conceptually correct
But, when customizing a search view with studio, the domain is written by the code, in JS
JSON parsable format `[["field", "=", "value"]]`
This should be supported too, as so many customizations may have been done before hand
After this commit, both expressions are supported by the filters menu
OPW 1957297, 1960732, 1965649 (at least)
closes odoo/odoo#32690
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/views/search/search_inputs.js | 3 | ||||
| -rw-r--r-- | addons/web/static/tests/views/search_view_tests.js | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/search/search_inputs.js b/addons/web/static/src/js/views/search/search_inputs.js index d92616cfe3e..efdacca9dc8 100644 --- a/addons/web/static/src/js/views/search/search_inputs.js +++ b/addons/web/static/src/js/views/search/search_inputs.js @@ -676,6 +676,9 @@ var FilterGroup = Input.extend(/** @lends instance.web.search.FilterGroup# */{ .without('[]') .reject(_.isEmpty) .map(function (domain) { + if (typeof domain !== 'string') { + domain = JSON.stringify(domain); + } domain = domain.replace(/%%/g, '%'); return domain; }) diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index 5d58e8d9cde..3e1070c4088 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -649,6 +649,37 @@ QUnit.module('Search View', { window.Date = RealDate; }); + QUnit.test('Filter with JSON-parsable domain works', function (assert) { + assert.expect(1); + + var domain = [['foo' ,'=', 'Gently Weeps']]; + var xml_domain = JSON.stringify(domain); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + mockRPC: function (route, args) { + if (route === '/web/dataset/search_read') { + assert.deepEqual(args.domain, domain, + 'A JSON parsable xml domain should be handled just like any other'); + } + return this._super.apply(this, arguments); + } + }); + + this.archs['partner,5,search'] = + '<search>'+ + '<filter string="Foo" name="gently_weeps" domain="' + _.escape(xml_domain) + '" />' + + '</search>'; + this.actions[0].search_view_id = [5, 'search']; + this.actions[0].context = {search_default_gently_weeps: true}; + + actionManager.doAction(1); + + actionManager.destroy(); + }); + QUnit.module('Favorites Menu'); QUnit.test('dynamic filters are saved dynamic', function (assert) { |
