From 53a9bdf900bdbff90b2653e5607fa794cc2650bd Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Thu, 27 Sep 2018 11:30:03 +0200 Subject: [PATCH] [FIX] web: only default time range works If a default time range was set in the action but no other default filter or groupby, the time range wasn't applied. This commit fixes that situation. --- .../static/src/js/views/search/search_view.js | 2 +- .../static/tests/views/search_view_tests.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/search/search_view.js b/addons/web/static/src/js/views/search/search_view.js index 145268622fe..69a45649793 100644 --- a/addons/web/static/src/js/views/search/search_view.js +++ b/addons/web/static/src/js/views/search/search_view.js @@ -483,7 +483,7 @@ var SearchView = Widget.extend({ this.hasFavorites = true; return this.favorite_menu.toggle_filter(default_custom_filter, true); } - if (!_.isEmpty(this.search_defaults)) { + if (!_.isEmpty(this.search_defaults) || this.timeRanges) { var inputs = this.search_fields.concat(this.filters, this.groupbys); var search_defaults = _.invoke(inputs, 'facet_for_defaults', this.search_defaults); var defaultTimeRange = this._searchDefaultTimeRange(); diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index a65d0b51390..92327bec671 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -787,5 +787,32 @@ QUnit.module('Search View', { actionManager.destroy(); }); + QUnit.test('a default time range only in context is taken into account', function (assert) { + assert.expect(2); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + mockRPC: function (route, args) { + // there are two read_group calls (for the groupby lists [] and ["date_field:day"]) + if (route === '/web/dataset/call_kw/partner/read_group') { + var timeRangeMenuData = args.kwargs.context.timeRangeMenuData; + assert.ok(timeRangeMenuData.timeRange.length > 0, "time range should be non empty"); + } + return this._super.apply(this, arguments); + }, + }); + + actionManager.doAction({ + res_model: 'partner', + type: 'ir.actions.act_window', + views: [[false, 'pivot']], + context: {time_ranges: {range: 'today', field: 'date_field'}} + }); + + actionManager.destroy(); + }); + }); });