diff options
| author | Denis Ledoux <dle@odoo.com> | 2016-03-16 11:54:21 +0100 |
|---|---|---|
| committer | Denis Ledoux <dle@odoo.com> | 2016-03-16 12:01:20 +0100 |
| commit | 1aeb747c6e06f11a005331713e5858438cdf8a60 (patch) | |
| tree | 878a8eb79ad213b3c4c68cc3dd14b2f9f82e598f /addons/web/static/src/js/framework/pyeval.js | |
| parent | 083e172dd969303fc818e6a769caea82cec86527 (diff) | |
[FIX] web: len & non zero implementation for wrapping list/dict
The implementation of `__len__` & `__nonzero__`
were not defined for the py types `wrapping_dict`
and `wrapping_list`.
For instance, this prevented an empty list
to be considered as `False` in domains
evaluated by the web client.
e.g., in the automatic partner merge wizard,
the domain
```
[('id', 'in', partner_ids and partner_ids[0] and partner_ids[0][2] or False)]
```
is used.
When the `partner_ids` list was empty (meaning the "partners to merge" list
was empty in the wizard), it wasn't considered as
`False`, and it therefore attempted to get
`partner_ids[0]`, which resulted to a crash, as
the list was empty.
opw-672095
Closes #11343
Courtesy of Xavier Morel (xmo@odoo.com)
Diffstat (limited to 'addons/web/static/src/js/framework/pyeval.js')
| -rw-r--r-- | addons/web/static/src/js/framework/pyeval.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/addons/web/static/src/js/framework/pyeval.js b/addons/web/static/src/js/framework/pyeval.js index ce25e7af534..2b553d37e0f 100644 --- a/addons/web/static/src/js/framework/pyeval.js +++ b/addons/web/static/src/js/framework/pyeval.js @@ -757,6 +757,12 @@ var wrapping_dict = py.type('wrapping_dict', null, { __getattr__: function (key) { return this.__getitem__(py.str.fromJSON(key)); }, + __len__: function () { + return Object.keys(this._store).length + }, + __nonzero__: function () { + return py.PY_size(this) > 0 ? py.True : py.False; + }, get: function () { var args = py.PY_parseArgs(arguments, ['k', ['d', py.None]]); @@ -780,6 +786,12 @@ var wrapping_list = py.type('wrapping_list', null, { __getitem__: function (index) { return wrap(this._store[index.toJSON()]); }, + __len__: function () { + return this._store.length; + }, + __nonzero__: function () { + return py.PY_size(this) > 0 ? py.True : py.False; + }, fromJSON: function (ar) { var instance = py.PY_call(wrapping_list); instance._store = ar; |
