summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-04-13 10:21:48 +0200
committerAaron Bohy <aab@odoo.com>2017-04-13 14:31:24 +0200
commit6b936ba2030e1cb3c6abdaf7f9486afde4ef49ef (patch)
tree6d8a0722c15b496af10f204beb2cbc3fa684d005 /addons/web/static/src/js/views/basic/basic_model.js
parentfce45c3361ac55292fc545bdf17b33e37a3dd242 (diff)
[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.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js10
1 files changed, 6 insertions, 4 deletions
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) {