diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-10-17 16:29:35 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-10-17 18:21:47 +0200 |
| commit | d365a289d4ed3f557fa46155419f5f517860fe9c (patch) | |
| tree | a8d14194533d813abcdc2328e423b95c025143a7 /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | a1e15b9fced014e58185b161b80eb34692b1474a (diff) | |
[FIX] web: generate proper x2many commands in some cases
When creating a new record with a non empty default value for a one2many
field, we did send the command 0 (for each one2many line) instead of the
command 1 (update). This was a pretty big problem, because then the
server would try to create a line with possibly incomplete data.
For example, it was not possible to create expense sheets: go to expense
menu, select one expense in the list view, click on the action menu
'submit to manager', this opens a form view with a one2many with the
selected expense, then save. Before this commit, this would lead to a
server error.
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.js | 16 |
1 files changed, 13 insertions, 3 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 073d8599f06..8798e8cdb2e 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -875,7 +875,10 @@ var BasicModel = AbstractModel.extend({ // id never changes, and should not be written delete record._changes.id; } - var changes = self._generateChanges(record, {viewType: options.viewType}); + var changes = self._generateChanges(record, {viewType: options.viewType, changesOnly: method !== 'create'}); + + // id field should never be written/changed + delete changes.id; if (method === 'create') { var fieldNames = record.getFieldNames(); @@ -2438,7 +2441,7 @@ var BasicModel = AbstractModel.extend({ changes = _.extend({}, record.data, record._changes); } else { changes = _.extend({}, record._changes); - }; + } var withReadonly = options.withReadonly || false; var commands = this._generateX2ManyCommands(record, { changesOnly: 'changesOnly' in options ? options.changesOnly : true, @@ -2475,6 +2478,7 @@ var BasicModel = AbstractModel.extend({ changes[fieldName] = false; } } + return changes; }, /** @@ -2621,7 +2625,13 @@ var BasicModel = AbstractModel.extend({ // this is a new id relRecord = _.findWhere(relRecordAdded, {res_id: list.res_ids[i]}); changes = this._generateChanges(relRecord, options); - commands[fieldName].push(x2ManyCommands.create(changes)); + if ('id' in changes) { + var id = changes.id; + delete changes.id; + commands[fieldName].push(x2ManyCommands.update(id, changes)); + } else { + commands[fieldName].push(x2ManyCommands.create(changes)); + } } } if (options.changesOnly && !didChange && addedIds.length === 0 && removedIds.length === 0) { |
