[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>
This commit is contained in:
Lucas Perais (lpe)
2019-04-15 12:41:26 +00:00
parent 6a57ad66b8
commit 7bf25cc333
2 changed files with 34 additions and 0 deletions
@@ -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;
})
@@ -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) {