[FIX] web: List editable top select last row

Before this commit, when we have a list (editable top) in a form
with some mandatory fields and some existing rows. If we click on
'add a line', a new empty line appear on the top, then we click on
the last row, the empty row will disappear and we will have a
traceback.

After this commit, if we repeat this scenario, we click on the last
row, we will be able to edit this last row.

closes odoo/odoo#38471

X-original-commit: 996f77b03eaf6dd646b1816e7f70209d5ee6f8df
Signed-off-by: jbm-odoo <jbm-odoo@users.noreply.github.com>
This commit is contained in:
jbm-odoo
2019-10-11 09:15:09 +00:00
committed by fw-bot
parent 93c657914c
commit 3fa123d69f
2 changed files with 38 additions and 1 deletions
@@ -1218,11 +1218,11 @@ ListRenderer.include({
return Promise.resolve();
}
var wrap = options.wrap === undefined ? true : options.wrap;
var recordID = this._getRecordID(rowIndex);
// Select the row then activate the widget in the correct cell
var self = this;
return this._selectRow(rowIndex).then(function () {
var recordID = self._getRecordID(rowIndex);
var record = self._getRecord(recordID);
if (fieldIndex >= (self.allFieldWidgets[record.id] || []).length) {
return Promise.reject();
@@ -917,6 +917,43 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('editable list view: click on last element after creation empty new line', async function (assert) {
assert.expect(1);
this.data.bar = {
fields: {
titi: {string: "Char", type: "char", required: true},
int_field: {string: "int_field", type: "integer", sortable: true, required: true}
},
records: [
{id: 1, titi: 'cui', int_field: 2},
{id: 2, titi: 'cuicui', int_field: 4},
],
};
this.data.foo.records[0].o2m = [1, 2];
var form = await createView({
View: FormView,
model: 'foo',
data: this.data,
res_id: 1,
viewOptions: { mode: 'edit' },
arch: '<form>'+
'<field name="o2m">'+
'<tree editable="top">'+
'<field name="int_field" widget="handle"/>'+
'<field name="titi"/>'+
'</tree>'+
'</field>'+
'</form>',
});
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add > a'));
await testUtils.dom.click(form.$('.o_data_row:last() > td.o_list_char'));
// This test ensure that they aren't traceback when clicking on the last row.
assert.containsN(form, '.o_data_row', 2, "list should have exactly 2 rows");
form.destroy();
});
QUnit.test('basic operations for editable list renderer', async function (assert) {
assert.expect(2);