summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorlen-odoo <len@odoo.com>2018-06-27 13:54:36 +0200
committerlen-odoo <35492570+len-odoo@users.noreply.github.com>2018-07-05 15:03:37 +0200
commit7764db7a34f05b55b56c2301f9c0b2a0098c2939 (patch)
treecc709fc7ada18871d3dd6a24e1c7f612858c5245 /addons/web/static/src/js/views/basic/basic_model.js
parent7af09db878997d1e5af09e4a3c314e6df5311e55 (diff)
[FIX] web: handle onchange on a on2many with an embedded one2many on multiple pages
Suppose there is a one2many field embedded in a one2many, (say we are viewing record A with one2many field B itself with a one2many C). Furthermore, there is a second page of the one2many field B. If an onchange is applied on B, then the server replies with a 1 command for all B records attached to the currently viewed object A. This includes a list of commands [[5], [4, C_id]*] for each B record, in particular B records that are on the second page. Since they are on the second page, they might not have been fetched by the frontend; in that case the corresponding C_ids are thus unknown. As a consequence, on save the frontend sends a command 0 to create the records for all unknown C_ids. Since it doesn't have any value to give to the 0 command, the row creation usually crash in the backend. Another wrong behaviour is fixed at the same time: if the server sends an update on the list of C ids with 4 commands. In that case, if the record has not been prefetched, we have no way to know if the list changed or not. To solve this, when we receive the 4 commands by the server, we send back 4 commands. coauthored by @aab-odoo opw 1835936
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.js7
1 files changed, 2 insertions, 5 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 32fb23d983a..7621fe35446 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -2860,13 +2860,10 @@ var BasicModel = AbstractModel.extend({
continue;
}
changes = this._generateChanges(relRecord, options);
- if (changes.id) {
+ if (!this.isNew(relRecord.id)) {
// the subrecord already exists in db
+ commands[fieldName].push(x2ManyCommands.link_to(relRecord.res_id));
delete changes.id;
- if (this.isNew(record.id)) {
- // if the main record is new, link the subrecord to it
- commands[fieldName].push(x2ManyCommands.link_to(relRecord.res_id));
- }
if (!_.isEmpty(changes)) {
commands[fieldName].push(x2ManyCommands.update(relRecord.res_id, changes));
}