[FIX] web: new record with o2m also with new records prevent name_get

Have a model A with a o2m to B.
In the list have a field  B > m2o > C

Also have a sequence field (widget handle) on B

Then Create a record A
Arrange yourself to have two new records B popping right away (through an onchange)
in the o2m. Their C field have to be empty

Resequence those two B lines with the handle

Before this commit, there was a traceback when trying to do an name_get on the C fields
Since both of them are empty, there is no record in the localData
Hence, no model. And also no records anyway, so no need to do a name_get

After this commit, there is no traceback, the name_get is avoided when no data is to be fetched

OPW 1853088
closes #24988
This commit is contained in:
Lucas Perais (lpe)
2018-06-06 09:51:56 +02:00
parent 6ad1a36b6e
commit 654ee788d9
2 changed files with 56 additions and 3 deletions
@@ -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',
@@ -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);