[FIX] web: prevent crash in some rare cases

When we have a form view with a one2many with an onchange, and with
lines which contains a x2many, and more lines that the limit (so more
than one page), and the read is not in the same order as what is
displayed because we have a widget=handle, then we might have a problem
when we delete one of the lines, if the onchanges tries to change the
x2many.

This is due to the fact that the order of the basicmodel datapoint is
not preserved by the various operations going around.  I think that we
may still have a few other issues of this type, but it is actually quite
difficult to establish.

In any case, this situation is now properly handled.

opw 804530
This commit is contained in:
Géry Debongnie
2018-01-11 16:30:34 +01:00
parent 8dcee7f17e
commit 27dd19c0b9
2 changed files with 41 additions and 1 deletions
@@ -2374,7 +2374,7 @@ var BasicModel = AbstractModel.extend({
});
record.data[fieldName] = list.id;
if (!fieldInfo.__no_fetch) {
var def = self._readUngroupedList(list).then(function () {
var def = self._readUngroupedList(list).then(function (list) {
return $.when(
self._fetchX2ManysBatched(list),
self._fetchReferencesBatched(list)
@@ -7600,6 +7600,46 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('one2many with multiple pages and sequence field', function (assert) {
assert.expect(1);
this.data.partner.records[0].turtles = [3, 2, 1];
this.data.partner.onchanges.turtles = function () {};
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"/>' +
'<field name="turtle_foo"/>' +
'<field name="partner_ids" invisible="1"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'onchange') {
return $.when({value: { turtles: [
[5],
[1, 1, {turtle_foo: "from onchange", partner_ids: [[5]]}],
]}});
}
return this._super(route, args);
},
viewOptions: {
mode: 'edit',
},
});
form.$('span[name="delete"]').first().click();
assert.strictEqual(form.$('.o_data_row').text(), 'from onchange',
'onchange has been properly applied');
form.destroy();
});
QUnit.module('FieldMany2Many');
QUnit.test('many2many kanban: edition', function (assert) {