From bc89bb79d2eac7db2861127bc41dcaf131568d4b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 5 Apr 2017 11:16:37 +0200 Subject: [FIX] web: BasicModel: ignore unknown fields after onchange It may happen that an onchange returns values for unknown fields in the view. In that case, the corresponding values need to be ignored as the postprocessing base on the field type can't be done, which may lead to errors later on (e.g. when saving). For example: one2many list in a form view which doesn't display a many2one field that exists on the related model. If an onchange on the main form view updates the value of the many2one inside the one2many, it will crash later on when the user will try to save (because the value [id, display_name] will be sent to the server). --- addons/web/static/src/js/views/basic/basic_model.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 304f7e475f7..47d5cee5c9c 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -942,10 +942,16 @@ var BasicModel = AbstractModel.extend({ params.res_id = command[1]; } rec = self._makeDataPoint(params); - var data = command[2]; - _.each(Object.keys(data), function (name) { + var data = {}; + _.each(Object.keys(command[2]), function (name) { var field = rec.fields[name]; - if (field && field.type === 'many2one') { + if (!field) { + // ignore if this field is unknown as we don't + // know if it requires a special handling + return; + } + data[name] = command[2][name]; + if (field.type === 'many2one') { var r = self._makeDataPoint({ modelName: field.relation, data: { @@ -957,9 +963,6 @@ var BasicModel = AbstractModel.extend({ } }); rec._changes = data; - for (var f in rec._changes) { - rec.data[f] = null; - } list._changes.push(rec.id); } if (command[0] === 5) { -- cgit v1.2.3