[FIX] web: fix crash when creating record with too many default values
When creating a record with many default values, it could happen that the number of ids returned by the default get (or onchange) exceeds the limit for the form view. For example, we can see the issue in the expenses list view. We can increase the limit in the pager, to a value higher than 40. Then, clicking on select all, then on 'Submit to manager' in the action menu will result in a traceback. The Submit to manager action will trigger a new action with a context key 'active_ids' with a large number of ids. After that, the web client will execute the server actions, which will return a new action with a context key 'default_expense_line_ids' with a bunch of ids. Then, it will attempt to create a form view. This will call the makeDefaultRecord method in the basic model. This method will generate the commands for the one2many, for all ids, but will only load the 40 first sub records. After, it will attempt to apply the onchanges, with some code that assumes that all operations of type 'ADD' correspond to a local datapoint. In this commit, we fix the code to properly work with operations of type ADD with a res_id, but with no id. In that case, we simply generate a command 'LINK_TO', since the value has not been changed. opw 804370
This commit is contained in:
@@ -2641,7 +2641,7 @@ var BasicModel = AbstractModel.extend({
|
||||
var relRecordAdded = [];
|
||||
var relRecordUpdated = [];
|
||||
_.each(list._changes, function (change) {
|
||||
if (change.operation === 'ADD') {
|
||||
if (change.operation === 'ADD' && change.id) {
|
||||
relRecordAdded.push(self.localData[change.id]);
|
||||
} else if (change.operation === 'UPDATE' && !self.isNew(change.id)) {
|
||||
// ignore new records that would have been updated
|
||||
@@ -2700,6 +2700,10 @@ var BasicModel = AbstractModel.extend({
|
||||
} else if (_.contains(addedIds, list.res_ids[i])) {
|
||||
// this is a new id (maybe existing in DB, but new in JS)
|
||||
relRecord = _.findWhere(relRecordAdded, {res_id: list.res_ids[i]});
|
||||
if (!relRecord) {
|
||||
commands[fieldName].push(x2ManyCommands.link_to(list.res_ids[i]));
|
||||
continue;
|
||||
}
|
||||
changes = this._generateChanges(relRecord, options);
|
||||
if (changes.id) {
|
||||
// the subrecord already exists in db
|
||||
|
||||
@@ -7680,6 +7680,34 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('new record, with one2many with more default values than limit', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch:'<form string="Partners">' +
|
||||
'<field name="turtles">' +
|
||||
'<tree limit="2">' +
|
||||
'<field name="turtle_foo"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
context: { default_turtles: [1,2,3]},
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
});
|
||||
assert.strictEqual(form.$('.o_data_row').text(), 'yopblip',
|
||||
'data has been properly loaded');
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
|
||||
assert.strictEqual(form.$('.o_data_row').text(), 'yopblip',
|
||||
'data has been properly saved');
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldMany2Many');
|
||||
|
||||
QUnit.test('many2many kanban: edition', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user