diff options
| author | Géry Debongnie <ged@odoo.com> | 2021-03-03 10:02:33 +0000 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2021-03-03 12:35:16 +0000 |
| commit | 8dbd1efef899fb637acca3c318ae99cb23838b8f (patch) | |
| tree | abe54eb9a966b6c4798553f4ba74af6ac83e3dac /addons/web/static/src/js/views/basic | |
| parent | 2d7f45e76607736bcc4f37bec480967ae2b373d7 (diff) | |
[FIX] web: issue with field named "length"
The underscore (_) library has a bug in which the _.each method does not
work with object which contains a "length" property. This is because it
does look for that key and if it is a number, it will assume that it is
an array with that length value. Nicely done...
If that length value is set to 0, then it will just do nothing, since it
thinks that it is dealing with an empty array.
Note that if the value is set to an object, _.each is smart enough to
notice that it cannot be an array, and will do the correct thing in this
case.
Usually, our _.each calls are safe, since we usually iterate on arrays,
or on object with safe keys, or on object with values that cannot be a
number.
But there was 2 unsafe calls in basic_model, which leads to strange
bugs: some code is skipped, and the form view is then confused. The
motivation for this fix is the fact that onchanges are not applied at
all, if there is a length field set to 0.
To fix this, we can just avoid using _.each. Note to every Odoo JS
developers reading this: new Odoo code should avoid using the _ and $
libraries, because we do not really need them, and we want to keep our
dependencies to the strict mininum.
OPW: #2465808
closes odoo/odoo#66126
closes odoo/odoo#67138
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 11 |
1 files changed, 6 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 d4d640d2739..e006f6bf8f9 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1102,9 +1102,9 @@ var BasicModel = AbstractModel.extend({ // save the viewType of edition, so that the correct readonly modifiers // can be evaluated when the record will be saved - _.each((record._changes || {}), function (value, fieldName) { + for (let fieldName in (record._changes || {})) { record._editionViewType[fieldName] = options.viewType; - }); + } } var shouldReload = 'reload' in options ? options.reload : true; var method = self.isNew(recordID) ? 'create' : 'write'; @@ -1666,7 +1666,8 @@ var BasicModel = AbstractModel.extend({ const viewType = options.viewType || record.viewType; record._changes = record._changes || {}; - _.each(values, function (val, name) { + for (let name in (values || {})) { + const val = values[name]; var field = record.fields[name]; if (!field) { // this field is unknown so we can't process it for now (it is not @@ -1685,7 +1686,7 @@ var BasicModel = AbstractModel.extend({ // if (options.firstOnChange) { // record._changes[name] = val; // } - return; + continue; } if (record._rawChanges[name]) { // if previous _rawChanges exists, clear them since the field is now knwon @@ -1847,7 +1848,7 @@ var BasicModel = AbstractModel.extend({ record._changes[name] = newValue; } } - }); + } return Promise.all(defs); // inner function that adds a record (based on its res_id) to a list |
