diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-02-05 10:34:51 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-02-12 09:32:17 +0000 |
| commit | e95ccf0908c263f6cf23c91c477a8e252e936ff1 (patch) | |
| tree | f5e7b10ebf7726a9f17598f0407d0a8cb14298c3 /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 968638aa1a158d24789ba6f0374436c74f807f2e (diff) | |
[FIX] *: domains should not have as many binary operator as there are terms
* modify client-side domain normalisation to error if the domain is
invalid (not enough terms / segments for the number of operators)
* add better error reporting to attrs / modifiers parsing
* add a few layered error augmentation to provide clearer context
e.g. "error: invalid domain <thing>" is helpful but "error while
parsing modifiers for field foo: modifier invisible: invalid domain
<thing>" is much more helpful
* rework _evalModifiers to deduplicate it in order to more easily
implement this contextual augmentation
* test that improper domains are properly found improper
* fix a bunch of incorrect attrs domains
* also removed an apparently undefined (& unused) "options" argument
to a _applyModifiers call
closes odoo/odoo#44642
Related: odoo/enterprise#8175
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 36 |
1 files changed, 16 insertions, 20 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 1ed8c36bb98..532af65744c 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2259,31 +2259,27 @@ var BasicModel = AbstractModel.extend({ * context. * @param {Object} modifiers * @returns {Object} + * @throws {Error} if one of the modifier domains is invalid */ _evalModifiers: function (element, modifiers) { - var result = {}; - var self = this; - var evalContext; - function evalModifier(mod) { + let evalContext = null; + const evaluated = {}; + for (const k of ['invisible', 'column_invisible', 'readonly', 'required']) { + const mod = modifiers[k]; if (mod === undefined || mod === false || mod === true) { - return !!mod; + if (k in modifiers) { + evaluated[k] = !!mod; + } + continue; + } + try { + evalContext = evalContext || this._getEvalContext(element); + evaluated[k] = new Domain(mod, evalContext).compute(evalContext); + } catch (e) { + throw new Error(_.str.sprintf('for modifier "%s": %s', k, e.message)); } - evalContext = evalContext || self._getEvalContext(element); - return new Domain(mod, evalContext).compute(evalContext); - } - if ('invisible' in modifiers) { - result.invisible = evalModifier(modifiers.invisible); - } - if ('column_invisible' in modifiers) { - result.column_invisible = evalModifier(modifiers.column_invisible); - } - if ('readonly' in modifiers) { - result.readonly = evalModifier(modifiers.readonly); - } - if ('required' in modifiers) { - result.required = evalModifier(modifiers.required); } - return result; + return evaluated; }, /** * Fetch all name_gets for the many2ones in a group |
