summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-04-05 11:16:37 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitbc89bb79d2eac7db2861127bc41dcaf131568d4b (patch)
tree4d2e079c1a6e33f7533e294a969b44f1e1171462 /addons/web/static/src/js
parentab44cabc78ae256636b951018d7967b2bd830fcc (diff)
[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).
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js15
1 files changed, 9 insertions, 6 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 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) {