From 6b936ba2030e1cb3c6abdaf7f9486afde4ef49ef Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 13 Apr 2017 10:21:48 +0200 Subject: [FIX] web: correctly save many2manys inside one2manys In a form view, if a one2many list view contained a many2many field (e.g. widget many2many_tags), the commands for the embedded many2many weren't generated for newly created one2many subrecords, so this field couldn't be saved. --- addons/web/static/src/js/views/basic/basic_model.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 e5e7da7867b..4de6ca25187 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1718,6 +1718,8 @@ var BasicModel = AbstractModel.extend({ } else if (type === 'many2one' && fieldName in changes) { var value = changes[fieldName]; changes[fieldName] = value ? this.localData[value].res_id : false; + } else if (changes[fieldName] === null) { + changes[fieldName] = false; } } return changes; @@ -1797,13 +1799,13 @@ var BasicModel = AbstractModel.extend({ // the didChange variable keeps track of the fact that at // least one id was updated var didChange = false; - var command, relRecord; + var changes, command, relRecord; for (var i = 0; i < relIds.length; i++) { if (_.contains(keptIds, relIds[i])) { // this is an id that already existed relRecord = _.findWhere(relData, {res_id: relIds[i]}); if (!_.isEmpty(relRecord._changes)) { - var changes = this._generateChanges(relRecord); + changes = this._generateChanges(relRecord); command = x2ManyCommands.update(relRecord.res_id, changes); didChange = true; } else { @@ -1813,8 +1815,8 @@ var BasicModel = AbstractModel.extend({ } else if (_.contains(addedIds, relIds[i])) { // this is a new id relRecord = _.findWhere(relData, {res_id: relIds[i]}); - relRecord = this.get(relRecord.id, {raw: true}); - commands[fieldName].push(x2ManyCommands.create(_.omit(relRecord.data, 'id'))); + changes = this._generateChanges(relRecord); + commands[fieldName].push(x2ManyCommands.create(changes)); } } if (changesOnly && !didChange && addedIds.length === 0 && removedIds.length === 0) { -- cgit v1.2.3