summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2018-10-12 14:29:51 +0000
committerSébastien Theys <seb@odoo.com>2018-10-12 14:29:51 +0000
commitc73efc27b72a0d3b6bbbd8d7d502d2a8e72bb68b (patch)
tree0776b5cad3341dbac1aa867b770629ad8da23b30
parent847ad7a44d65f1e965cda8acc9ffde92157c37d1 (diff)
[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
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js8
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js68
2 files changed, 75 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index f6bf46aed68..0afb65a9a88 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -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,
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index b63b2b25a0c..99f97fbda54 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -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: