From e1b68dae50a0ffd8eadeafd823acb328c429b7fe Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 16 Mar 2017 14:01:45 +0100 Subject: [PATCH] [FIX] web, *: fix domain building without CompoundDomain * board, google_spreadsheet Commit 8e0c7ccc77f358601b0701536fcb33842ca324a6 got rid of the CompoundDomain class but did not adapt the code correctly. - Domains have to be concatened, not regrouped in a big array - String domains have to be converted to array - "OR" joining must normalize subdomains first (add explicit "AND"s) --- addons/board/static/src/js/dashboard.js | 2 +- addons/google_spreadsheet/static/src/js/search.js | 2 +- addons/web/static/src/js/chrome/search_inputs.js | 6 ++++++ addons/web/static/test/chrome/search_tests.js | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/dashboard.js index 522b7fb19c2..4e6ab81fb66 100644 --- a/addons/board/static/src/js/dashboard.js +++ b/addons/board/static/src/js/dashboard.js @@ -404,7 +404,7 @@ FavoriteMenu.include({ domain = this.searchview.dataset.get_domain() || []; _.each(search_data.contexts, context.add, context); _.each(search_data.domains, function (d) { - domain.push(Domain.prototype.stringToArray(d)); + domain.push.apply(domain, Domain.prototype.stringToArray(d)); }); context.add({ diff --git a/addons/google_spreadsheet/static/src/js/search.js b/addons/google_spreadsheet/static/src/js/search.js index b715282e551..a9f8e392d0a 100644 --- a/addons/google_spreadsheet/static/src/js/search.js +++ b/addons/google_spreadsheet/static/src/js/search.js @@ -33,7 +33,7 @@ FavoriteMenu.include({ ds = new data.DataSet(this, 'google.drive.config'); _.each(sv_data.domains, function (d) { - domain.push(Domain.prototype.stringToArray(d)); + domain.push.apply(domain, Domain.prototype.stringToArray(d)); }); ds.call('set_spreadsheet', [model, Domain.prototype.arrayToString(domain), groupbys, list_view_id]) .done(function (res) { diff --git a/addons/web/static/src/js/chrome/search_inputs.js b/addons/web/static/src/js/chrome/search_inputs.js index 41676b98e2e..aa02f9fe950 100644 --- a/addons/web/static/src/js/chrome/search_inputs.js +++ b/addons/web/static/src/js/chrome/search_inputs.js @@ -170,6 +170,7 @@ var Field = Input.extend( /** @lends instance.web.search.Field# */ { return domains[0]; } + _.each(domains, Domain.prototype.normalizeArray); var ors = _.times(domains.length - 1, _.constant("|")); return ors.concat.apply(ors, domains); } @@ -619,10 +620,14 @@ var FilterGroup = Input.extend(/** @lends instance.web.search.FilterGroup# */{ * @return {*} combined domains of the enabled filters in this group */ get_domain: function (facet) { + var userContext = this.getSession().user_context; var domains = facet.values.chain() .map(function (f) { return f.get('value').attrs.domain; }) .without('[]') .reject(_.isEmpty) + .map(function (d) { + return Domain.prototype.stringToArray(d, userContext); + }) .value(); if (!domains.length) { @@ -632,6 +637,7 @@ var FilterGroup = Input.extend(/** @lends instance.web.search.FilterGroup# */{ return domains[0]; } + _.each(domains, Domain.prototype.normalizeArray); var ors = _.times(domains.length - 1, _.constant("|")); return ors.concat.apply(ors, domains); }, diff --git a/addons/web/static/test/chrome/search_tests.js b/addons/web/static/test/chrome/search_tests.js index 5d188f428ec..c2d290134ed 100644 --- a/addons/web/static/test/chrome/search_tests.js +++ b/addons/web/static/test/chrome/search_tests.js @@ -129,7 +129,6 @@ QUnit.module('chrome', {}, function () { assert.strictEqual(query.length, 0, 'Should have removed the facet'); }); - QUnit.test('Intermediate emptiness should not remove the facet', function (assert) { assert.expect(3); @@ -167,5 +166,7 @@ QUnit.module('chrome', {}, function () { ]); }); + // TODO add a test to check that combining two filters with a or normalizes the two filters before + // Note: maybe domain.js will be improved to make this easier }); });