[FIX] web: stabilize sequence for new records on last page

Before this commit, the compute sequence was relying on the fact the ID was used
as a secondary order key to get the right result.

This is necessary when adding items between pages because we don't resequence
the following elements.

However this was not necessary when adding new elements on the last page since
there are no following elements to resesquence in that case.

PR: #27639
This commit is contained in:
Sébastien Theys
2018-10-12 14:29:51 +00:00
parent 847ad7a44d
commit c73efc27b7
2 changed files with 75 additions and 1 deletions
@@ -398,8 +398,14 @@ var BasicModel = AbstractModel.extend({
// by 1 (at least until there is a gap in the numbering).
// We don't do it now because it's not an important case.
// However, we can for sure increment by 1 if we are on the last page.
var handleFieldValue = computedList.data[index].data[handleField];
handleFieldValue = position !== 'top' ? handleFieldValue : handleFieldValue - 1;
if (position === 'top') {
handleFieldValue--;
} else if (list.count <= list.offset + list.limit - (list.tempLimitIncrement || 0)) {
handleFieldValue++;
}
return {
field: handleField,
@@ -9552,6 +9552,74 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('one2many with sequence field, override default_get, not last page', function (assert) {
assert.expect(1);
this.data.partner.records[0].turtles = [3, 2, 1];
this.data.turtle.fields.turtle_int.default = 10;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<field name="turtles">' +
'<tree limit="2">' +
'<field name="turtle_int" widget="handle"/>' +
'</tree>' +
'<form>' +
'<field name="turtle_int"/>' +
'</form>' +
'</field>' +
'</form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
// click add a new line
// check turtle_int for new is the current max of the page
$('.o_field_x2many_list_row_add a').click();
assert.strictEqual($('.modal .o_input[name="turtle_int"]').val(), '10');
form.destroy();
});
QUnit.test('one2many with sequence field, override default_get, last page', function (assert) {
assert.expect(1);
this.data.partner.records[0].turtles = [3, 2, 1];
this.data.turtle.fields.turtle_int.default = 10;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<field name="turtles">' +
'<tree limit="4">' +
'<field name="turtle_int" widget="handle"/>' +
'</tree>' +
'<form>' +
'<field name="turtle_int"/>' +
'</form>' +
'</field>' +
'</form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
// click add a new line
// check turtle_int for new is the current max of the page +1
$('.o_field_x2many_list_row_add a').click();
assert.strictEqual($('.modal .o_input[name="turtle_int"]').val(), '22');
form.destroy();
});
QUnit.test('one2many with sequence field, fetch name_get from empty list, field text', function (assert) {
// There was a bug where a RPC would fail because no route was set.
// The scenario is: