From 43ce727568bd92a0f3f019cd4f5b6a1815a1960a Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 3 Mar 2020 13:33:13 +0000 Subject: [FIX] web: save all values returned by onchange MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's assume a form view with a boolean field and a one2many field, displayed for instance with widget many2many_tags. There is an onchange on the boolean field, which populates the one2many, e.g. [[5], [0, 0, {display_name: 'name', other_field: 'value'}]] Before this commit, only the display_name was sent to the server on save, because 'other_field' is unknown by the webclient. Similar situations occurred with one2manys displayed as lists, and onchanges returning values for fields that aren't in the list. These situations probably didn't exist in Odoo yet, but a pending task on website event adds one. This commit ensures that all values returned by the onchange for the x2many subrecords are sent back to the server when the user saves. closes odoo/odoo#46807 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/js/views/basic/basic_model.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (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 e5f20378dea..3063e56d0b1 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3369,6 +3369,21 @@ var BasicModel = AbstractModel.extend({ } } else { // the subrecord is new, so create it + + // we may have received values from an onchange for fields that are + // not in the view, and that we don't even know, as we don't have the + // fields_get of models of related fields. We save those values + // anyway, but for many2ones, we have to extract the id from the pair + // [id, display_name] + const rawChangesEntries = Object.entries(relRecord._rawChanges); + for (const [fieldName, value] of rawChangesEntries) { + const isMany2OneValue = Array.isArray(value) && + value.length === 2 && + Number.isInteger(value[0]) && + typeof value[1] === 'string'; + changes[fieldName] = isMany2OneValue ? value[0] : value; + } + commands[fieldName].push(x2ManyCommands.create(relRecord.ref, changes)); } } -- cgit v1.2.3