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 042f7bafa97179e74528e86555ddaa95c3373ccf..da0d58664c2c6e68b31d0fdef991d963d76343e6 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1972,9 +1972,7 @@ var BasicModel = AbstractModel.extend({ var records = []; var ids = []; list = this._applyX2ManyOperations(list); - if (_.isEmpty(list.data)) { - return $.when(); - } + _.each(list.data, function (localId) { var record = self.localData[localId]; var data = record._changes || record.data; @@ -1985,6 +1983,9 @@ var BasicModel = AbstractModel.extend({ ids.push(many2oneRecord.res_id); model = many2oneRecord.model; }); + if (!ids.length) { + return $.when(); + } return this._rpc({ model: model, method: 'name_get', diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 022fa80227422185e198024b533bcbb57afca861..190e2949fe731b7d4ce91417f6b8bfd2702ef9fd 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2550,6 +2550,58 @@ QUnit.module('relational_fields', { QUnit.module('FieldOne2Many'); + QUnit.test('New record with a o2m also with 2 new records, ordered, and resequenced', function (assert) { + assert.expect(3); + + // Needed to have two new records in a single stroke + this.data.partner.onchanges = { + foo: function(obj) { + obj.p = [ + [5], + [0, 0, {trululu: false}], + [0, 0, {trululu: false}], + ] + } + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<field name="foo" />' + + '<field name="p">' + + '<tree editable="bottom" default_order="int_field">' + + '<field name="int_field" widget="handle"/>' + + '<field name="trululu"/>' + + '</tree>' + + '</field>' + + '</form>', + viewOptions: { + mode: 'create', + }, + mockRPC: function (route, args) { + assert.step(args.method + ' ' + args.model) + return this._super(route, args); + }, + }); + + // change the int_field through drag and drop + // that way, we'll trigger the sorting and the name_get + // of the lines of "p" + testUtils.dragAndDrop( + form.$('.ui-sortable-handle').eq(1), + form.$('tbody tr').first(), + {position: 'top'} + ); + + // Only those two should have been called + // name_get on trululu would trigger an traceback + assert.verifySteps(['default_get partner', 'onchange partner']); + + form.destroy(); + }); + QUnit.test('O2M List with pager, decoration and default_order: add and cancel adding', function (assert) { assert.expect(3);