[FIX] web: pivot view should not crash when sorting
This commit is contained in:
committed by
Aaron Bohy
parent
556ee204d0
commit
1c7fa2e72d
@@ -344,7 +344,7 @@ var PivotController = AbstractController.extend({
|
||||
var isAscending = $target.hasClass('o_pivot_measure_row_sorted_asc');
|
||||
this.model
|
||||
.sortRows(this.handle, col_id, measure, isAscending)
|
||||
.then(this.update_state.bind(this));
|
||||
.then(this.update.bind(this, {}, {reload: false}));
|
||||
},
|
||||
/**
|
||||
* This method is called when someone clicks on an open header. When that
|
||||
|
||||
@@ -284,21 +284,20 @@ var PivotModel = AbstractModel.extend({
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
sortRows: function (id, col_id, measure, descending) {
|
||||
var record = this.localData[id];
|
||||
|
||||
_traverseTree(record.data.main_row.root, function (header) {
|
||||
var cells = this.data.cells;
|
||||
this._traverseTree(this.data.main_row.root, function (header) {
|
||||
header.children.sort(compare);
|
||||
});
|
||||
record.sorted_column = {
|
||||
this.data.sorted_column = {
|
||||
id: col_id,
|
||||
measure: measure,
|
||||
order: descending ? 'desc' : 'asc',
|
||||
};
|
||||
function _getValue (id1, id2) {
|
||||
if ((id1 in record.data.cells) && (id2 in record.data.cells[id1])) {
|
||||
return record.data.cells[id1][id2];
|
||||
if ((id1 in cells) && (id2 in cells[id1])) {
|
||||
return cells[id1][id2];
|
||||
}
|
||||
if (id2 in record.data.cells) return record.data.cells[id2][id1];
|
||||
if (id2 in cells) return cells[id2][id1];
|
||||
}
|
||||
|
||||
function compare (row1, row2) {
|
||||
|
||||
@@ -452,4 +452,33 @@ QUnit.module('Views', {
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('can sort data in a column by clicking on header', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot>' +
|
||||
'<field name="foo" type="measure"/>' +
|
||||
'<field name="product_id" type="row"/>' +
|
||||
'</pivot>',
|
||||
});
|
||||
|
||||
assert.strictEqual($('td.o_pivot_cell_value').text(), "321220",
|
||||
"should have proper values in cells (total, result 1, result 2");
|
||||
|
||||
pivot.$('th.o_pivot_measure_row').click();
|
||||
|
||||
assert.strictEqual($('td.o_pivot_cell_value').text(), "322012",
|
||||
"should have proper values in cells (total, result 2, result 1");
|
||||
|
||||
pivot.$('th.o_pivot_measure_row').click();
|
||||
|
||||
assert.strictEqual($('td.o_pivot_cell_value').text(), "321220",
|
||||
"should have proper values in cells (total, result 1, result 2");
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
});});
|
||||
|
||||
Reference in New Issue
Block a user