[FIX] web: ListView: reset selection when reloading

Before this rev., the list of selected records wasn't correctly
reset when the list was reloaded (e.g. when coming back using the
breadcrumbs). In the UI, the records weren't selected anymore, but
in javascript, the list of selected records wasn't empty. As a
consequence, the aggregates were wrongly computed, and always
displayed 0.

Closes #22725.
This commit is contained in:
Aaron Bohy
2018-02-12 11:11:43 +01:00
parent b6d156ad7a
commit 0982ceaa37
2 changed files with 35 additions and 0 deletions
@@ -72,6 +72,7 @@ var ListRenderer = BasicRenderer.extend({
*/
updateState: function (state, params) {
this._processColumns(params.columnInvisibleFields || {});
this.selection = [];
return this._super.apply(this, arguments);
},
@@ -582,6 +582,40 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('selection is reset on reload', function (assert) {
assert.expect(5);
var list = createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree>' +
'<field name="foo"/>' +
'<field name="int_field" sum="Sum"/>' +
'</tree>',
});
assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32',
"total should be 32 (no record selected)");
// select first record
var $firstRowSelector = list.$('tbody .o_list_record_selector input').first();
$firstRowSelector.click();
assert.ok($firstRowSelector.is(':checked'), "first row should be selected");
assert.strictEqual(list.$('tfoot td:nth(2)').text(), '10',
"total should be 10 (first record selected)");
// reload
list.reload();
$firstRowSelector = list.$('tbody .o_list_record_selector input').first();
assert.notOk($firstRowSelector.is(':checked'),
"first row should no longer be selected");
assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32',
"total should be 32 (no more record selected)");
list.destroy();
});
QUnit.test('aggregates are computed correctly', function (assert) {
assert.expect(4);