From 64d7da419885301fa2c1b26bf3cde286052cefba Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 2 Oct 2018 11:21:30 +0200 Subject: [PATCH] [FIX] web: fix update problems in graph view The graph view was not updated correctly with respect to time range menu data. We fix that problem in this commit. --- .../static/src/js/views/graph/graph_model.js | 11 +++++++++++ .../src/js/views/graph/graph_renderer.js | 10 ++++++++++ .../static/tests/views/search_view_tests.js | 19 +++++++++++++------ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/views/graph/graph_model.js b/addons/web/static/src/js/views/graph/graph_model.js index fa9a7180e06..adefe1e8953 100644 --- a/addons/web/static/src/js/views/graph/graph_model.js +++ b/addons/web/static/src/js/views/graph/graph_model.js @@ -101,6 +101,17 @@ return AbstractModel.extend({ this.chart.groupedBy = params.context.graph_groupbys || this.chart.groupedBy; this.chart.measure = params.context.graph_measure || this.chart.measure; this.chart.mode = params.context.graph_mode || this.chart.mode; + var timeRangeMenuData = params.context.timeRangeMenuData; + if (timeRangeMenuData) { + this.chart.timeRange = timeRangeMenuData.timeRange || []; + this.chart.comparisonTimeRange = timeRangeMenuData.comparisonTimeRange || []; + this.chart.compare = this.chart.comparisonTimeRange.length > 0; + } else { + this.chart.timeRange = []; + this.chart.comparisonTimeRange = []; + this.chart.compare = false; + this.chart = _.omit(this.chart, 'comparisonData'); + } } if ('domain' in params) { this.chart.domain = params.domain; diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js index c2bb79c491f..470d064ef68 100644 --- a/addons/web/static/src/js/views/graph/graph_renderer.js +++ b/addons/web/static/src/js/views/graph/graph_renderer.js @@ -68,6 +68,16 @@ return AbstractRenderer.extend({ this._super.apply(this, arguments); this.isInDOM = false; }, + /** + * @override + * @param {Object} state + * @param {Object} params + */ + updateState: function (state, params) { + this.isComparison = !!state.comparisonData; + this.stacked = this.isComparison ? false : params.stacked; + return this._super.apply(this, arguments); + }, //-------------------------------------------------------------------------- // Private diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index 92327bec671..6785160f280 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -723,6 +723,7 @@ QUnit.module('Search View', { assert.expect(43); var self = this; + var nbrReadGroup = 0; var periodOptionText, periodOptionValue; var unpatchDate = patchDate(2017, 2, 22, 1, 0, 0); @@ -733,14 +734,20 @@ QUnit.module('Search View', { data: this.data, mockRPC: function (route, args) { if (route === '/web/dataset/call_kw/partner/read_group') { + nbrReadGroup++; var timeRangeMenuData = args.kwargs.context.timeRangeMenuData; if (timeRangeMenuData) { - assert.deepEqual(timeRangeMenuData.timeRange, - self.periodDomains.shift(), - "time range domain for " + periodOptionText); - assert.deepEqual(timeRangeMenuData.comparisonTimeRange, - self.previousPeriodDomains.shift(), - "comparaison time range domain for " + periodOptionText); + // nbrReadGroup % 2 === 0 is true when the read group is for data, false + // for comparison data + if (nbrReadGroup % 2 === 0) { + assert.deepEqual(timeRangeMenuData.timeRange, + self.periodDomains.shift(), + "time range domain for " + periodOptionText); + } else { + assert.deepEqual(timeRangeMenuData.comparisonTimeRange, + self.previousPeriodDomains.shift(), + "comparaison time range domain for " + periodOptionText); + } } } return this._super.apply(this, arguments);