diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-03-08 16:43:44 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 29cd7154e66a30fb656b88e16b4301d17fa7d958 (patch) | |
| tree | 4f1adf4c812aa38a1a9029c4e13d0beac26b45ee /addons/web/static/src/js/fields/field_utils.js | |
| parent | b5b649e5b21d41279f12f0dbe6cfa53ca2c52580 (diff) | |
[FIX] web: restore FieldStatus behavior
FieldStatus was broken:
- With a selection, the statusbar_visible attribute forces the choices
to display, the discarded ones do not appear at all (even folded)
- With a m2o, the fold_field option tells the field to check in the
relation to know if the choice has to be folded or not, this was not
properly supported
- Changing a m2o value was broken as the parseMany2one function did
not exist
- The status were misordered
- ...
* Also refactor the way the rendering is handled.
* Also modify all statusbar tests so that the statusbar widget is
placed in the form header tag (as it is the common use case).
Diffstat (limited to 'addons/web/static/src/js/fields/field_utils.js')
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index c359a014b4e..406a86ac7a2 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -336,6 +336,34 @@ function parseMonetary(formatted_value) { return parseFloat(value); } +/** + * Creates an object with id and display_name. + * + * @param {Array|number|string|Object} value + * The given value can be : + * - an array with id as first element and display_name as second element + * - a number or a string representing the id (the display_name will be + * returned as undefined) + * - an object, simply returned untouched + * @returns {Object} (contains the id and display_name) + * Note: if the given value is not an array, a string or a + * number, the value is returned untouched. + */ +function parseMany2one(value) { + if (_.isArray(value)) { + return { + id: value[0], + display_name: value[1], + }; + } + if (_.isNumber(value) || _.isString(value)) { + return { + id: parseInt(value, 10), + }; + } + return value; +} + return { format: { binary: _.identity, // todo @@ -368,7 +396,7 @@ return { id: _.identity, integer: parseInteger, many2many: _.identity, // todo - many2one: _.identity, + many2one: parseMany2one, monetary: parseMonetary, one2many: _.identity, reference: _.identity, // todo |
