diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js index 466350d5e99..9abfa4861b6 100644 --- a/addons/web/static/src/js/views/pivot/pivot_model.js +++ b/addons/web/static/src/js/views/pivot/pivot_model.js @@ -235,8 +235,8 @@ var PivotModel = AbstractModel.extend({ additionalHeaders = additionalHeaders.concat( _.map( [ - this.data.timeRangeDescription, - this.data.comparisonTimeRangeDescription, + this.data.timeRangeDescription.toString(), + this.data.comparisonTimeRangeDescription.toString(), 'Variation' ], makeMeasure diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 66fb366e055..3bad47347ec 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -1269,6 +1269,94 @@ QUnit.module('Views', { // Test to modify and extend assert.strictEqual($('.o_pivot p.o_view_nocontent_empty_folder').length, 1); + unpatchDate(); + actionManager.destroy(); + }); + + QUnit.test('export data in excel with comparison', function (assert) { + assert.expect(10); + + this.data.partner.records[0].date = '2016-12-15'; + this.data.partner.records[1].date = '2016-12-17'; + this.data.partner.records[2].date = '2016-11-22'; + this.data.partner.records[3].date = '2016-11-03'; + + var unpatchDate = patchDate(2016, 11, 20, 1, 0, 0); + + // create an action manager to test the interactions with the search view + var actionManager = createActionManager({ + data: this.data, + archs: { + 'partner,false,pivot': '' + + '' + + '' + + '', + 'partner,false,search': '', + }, + session: { + get_file: function (args) { + var data = JSON.parse(args.data.data); + _.each(data.headers, function (l) { + assert.step(l.map(function (o) {return o.title;})); + }); + assert.step(data.measure_row.map(function (o) {return o.measure;})); + assert.step(data.nbr_measures); + assert.step(data.rows.map(function (o) {return o.values.length;})); + assert.strictEqual(args.url, '/web/pivot/export_xls', + "should call get_file with correct parameters"); + args.complete(); + }, + }, + }); + + actionManager.doAction({ + res_model: 'partner', + type: 'ir.actions.act_window', + views: [[false, 'pivot']], + }); + + // open time range menu + $('.o_control_panel .o_time_range_menu_button').click(); + // check checkbox 'Compare To' + $('.o_control_panel .o_time_range_menu .o_comparison_checkbox').click(); + // Click on 'Apply' button + $('.o_control_panel .o_time_range_menu .o_apply_range').click(); + + // the time range menu configuration is by now: Date, Today, checkbox checked, Previous Period + // With the data above, the time ranges contain no record. + assert.strictEqual($('.o_pivot p.o_view_nocontent_empty_folder').length, 1, "there should be no data"); + // export data should be impossible since the pivot buttons + // are deactivated (exception: the 'Measures' button). + assert.ok($('.o_control_panel button.o_pivot_download').prop('disabled')); + + // open time range menu + $('.o_control_panel .o_time_range_menu_button').click(); + // select 'This Month' as date range + $('.o_control_panel .o_time_range_selector').val('this_month'); + + // Click on 'Apply' button + $('.o_control_panel .o_time_range_menu .o_apply_range').click(); + // the time range menu configuration is by now: Date, This Month, checkbox checked, Previous Period + // With the data above, the time ranges contain some records. + // export data. Should execute 'get_file' + $('.o_control_panel button.o_pivot_download').click(); + + assert.verifySteps([ + // Headers + ["Total", ""], + ["December 2016" , "November 2016"], + ["Foo", "Foo", "Foo"], + [ + "This Month", "Previous Period", "Variation", + "This Month", "Previous Period", "Variation", + "This Month", "Previous Period", "Variation" + ], + // number of 'measures' + 3, + // rows values length + [9] + ]); + unpatchDate(); actionManager.destroy(); });