[FIX] web: BasicModel: don't update default one2many records
Let's assume a one2many field in a form view with a default value with commands 4 (link to). Before this rev., when saving the record, the BasicModel generated a command 4 and a command 1 (update) for each record, with the values of the record (directly coming from DB). This can cause an issue when the related record can't be edited (e.g. a posted journal entry in accounting). closes odoo/odoo#33797 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
@@ -3175,7 +3175,7 @@ var BasicModel = AbstractModel.extend({
|
||||
commands[fieldName].push(x2ManyCommands.link_to(list.res_ids[i]));
|
||||
continue;
|
||||
}
|
||||
changes = this._generateChanges(relRecord, options);
|
||||
changes = this._generateChanges(relRecord, _.extend({}, options, {changesOnly: true}));
|
||||
if (!this.isNew(relRecord.id)) {
|
||||
// the subrecord already exists in db
|
||||
commands[fieldName].push(x2ManyCommands.link_to(relRecord.res_id));
|
||||
|
||||
@@ -1676,9 +1676,7 @@ QUnit.module('fields', {}, function () {
|
||||
obj.turtles,
|
||||
[
|
||||
[4, 2, false],
|
||||
[1, 2, { turtle_foo: 'blip' }],
|
||||
[4, 3, false],
|
||||
[1, 3, { turtle_foo: 'kawa' }]
|
||||
],
|
||||
"should have properly created the x2many command list");
|
||||
};
|
||||
@@ -1702,14 +1700,9 @@ QUnit.module('fields', {}, function () {
|
||||
return Promise.resolve({ turtles: [[6, 0, [2, 3]]] });
|
||||
}
|
||||
if (args.method === 'create') {
|
||||
// it would be even better if we did not send the current
|
||||
// unchanged state with the command 1, but this seems more
|
||||
// difficult.
|
||||
assert.deepEqual(args.args[0].turtles, [
|
||||
[4, 2, false],
|
||||
[1, 2, { turtle_foo: 'blip' }],
|
||||
[4, 3, false],
|
||||
[1, 3, { turtle_foo: 'kawa' }]
|
||||
], 'should send proper commands to create method');
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
|
||||
Reference in New Issue
Block a user