[FIX] web: list: editable="top" with less than 4 records

Before this rev., when adding then discarding a new record in a
(main) editable="top" list, the record was added to the top of
the list, and then replaced by an empty row when discarding,
whereas that empty row should have been rendered below potential
data rows.
This commit is contained in:
Aaron Bohy
2019-04-12 06:14:08 +00:00
parent d43624b5c5
commit 6722e66517
2 changed files with 38 additions and 1 deletions
@@ -311,7 +311,16 @@ ListRenderer.include({
if (this.state.count >= 4) {
$row.remove();
} else {
$row.replaceWith(this._renderEmptyRow());
// we want to always keep at least 4 (possibly empty) rows
var $emptyRow = this._renderEmptyRow();
$row.replaceWith($emptyRow);
if (this.editable === "top") {
// move the empty row we just inserted after data rows
var $lastDataRow = this.$('.o_data_row:last');
if ($lastDataRow.length) {
$emptyRow.insertAfter($lastDataRow);
}
}
}
},
/**
@@ -359,6 +359,34 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('discard a new record in editable="top" list with less than 4 records', async function (assert) {
assert.expect(7);
var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top"><field name="bar"/></tree>',
domain: [['bar', '=', true]],
});
assert.containsN(list, '.o_data_row', 3);
assert.containsN(list, 'tbody tr', 4);
await testUtils.dom.click(list.$('.o_list_button_add'));
assert.containsN(list, '.o_data_row', 4);
assert.hasClass(list.$('tbody tr:first'), 'o_selected_row');
await testUtils.dom.click(list.$('.o_list_button_discard'));
assert.containsN(list, '.o_data_row', 3);
assert.containsN(list, 'tbody tr', 4);
assert.hasClass(list.$('tbody tr:first'), 'o_data_row');
list.destroy();
});
QUnit.test('basic grouped list rendering', async function (assert) {
assert.expect(4);