summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-05-19 19:28:22 +0200
committerGéry Debongnie <ged@odoo.com>2017-05-22 09:34:49 +0200
commit5e913677a5f5fe54fd4560b6caa986b9c7c61647 (patch)
tree17c5acd9d3fc2ee6834863c54c9d30a4f6b84b62
parentaf021f223b2ef3801fa012e82775054c48054b98 (diff)
[FIX] web: prevent crash when downloading pivot view
The download feature in the pivot view was broken since we introduced the new views. Simply clicking on the download button caused a traceback.
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_controller.js1
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_model.js14
-rw-r--r--addons/web/static/tests/views/pivot_tests.js24
3 files changed, 32 insertions, 7 deletions
diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js
index f132704a475..d6bac8020d4 100644
--- a/addons/web/static/src/js/views/pivot/pivot_controller.js
+++ b/addons/web/static/src/js/views/pivot/pivot_controller.js
@@ -126,6 +126,7 @@ var PivotController = AbstractController.extend({
return;
}
framework.blockUI();
+ table.title = this.title;
session.get_file({
url: '/web/pivot/export_xls',
data: {data: JSON.stringify(table)},
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 ab4a2eb0314..13618471a74 100644
--- a/addons/web/static/src/js/views/pivot/pivot_model.js
+++ b/addons/web/static/src/js/views/pivot/pivot_model.js
@@ -127,20 +127,21 @@ var PivotModel = AbstractModel.extend({
});
},
/**
+ * Export the current pivot view in a simple JS object.
+ *
* @returns {Object}
*/
exportData: function () {
- var record = this.data;
- var measureNbr = record.measures.length;
- var headers = this.renderer._computeHeaders();
+ var measureNbr = this.data.measures.length;
+ var headers = this._computeHeaders();
var measureRow = measureNbr > 1 ? _.last(headers) : [];
- var rows = this.renderer._computeRows();
+ var rows = this._computeRows();
var i, j, value;
headers[0].splice(0,1);
// process measureRow
for (i = 0; i < measureRow.length; i++) {
- measureRow[i].measure = this.measures[measureRow[i].measure].string;
+ measureRow[i].measure = this.fields[measureRow[i].measure].string;
}
// process all rows
for (i =0, j, value; i < rows.length; i++) {
@@ -148,7 +149,7 @@ var PivotModel = AbstractModel.extend({
value = rows[i].values[j];
rows[i].values[j] = {
is_bold: (i === 0) ||
- ((record.data.main_col.width > 1) &&
+ ((this.data.main_col.width > 1) &&
(j >= rows[i].values.length - measureNbr)),
value: (value === undefined) ? "" : value,
};
@@ -159,7 +160,6 @@ var PivotModel = AbstractModel.extend({
measure_row: measureRow,
rows: rows,
nbr_measures: measureNbr,
- title: this.title,
};
},
/**
diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js
index df7d4b9f7d8..0845e45046d 100644
--- a/addons/web/static/tests/views/pivot_tests.js
+++ b/addons/web/static/tests/views/pivot_tests.js
@@ -591,4 +591,28 @@ QUnit.module('Views', {
pivot.destroy();
});
+ QUnit.test('can download a file', function (assert) {
+ assert.expect(1);
+
+ var pivot = createView({
+ View: PivotView,
+ model: "partner",
+ data: this.data,
+ arch: '<pivot>' +
+ '<field name="date" interval="month" type="col"/>' +
+ '<field name="foo" type="measure"/>' +
+ '</pivot>',
+ session: {
+ get_file: function (args) {
+ assert.strictEqual(args.url, '/web/pivot/export_xls',
+ "should call get_file with correct parameters");
+ args.complete();
+ },
+ },
+ });
+
+ $('.o_pivot_download').click();
+ pivot.destroy();
+ });
+
});});