diff options
| author | David Monjoie <dmo@odoo.com> | 2017-07-03 10:46:10 +0200 |
|---|---|---|
| committer | David Monjoie <dmo@odoo.com> | 2017-07-18 15:51:49 +0200 |
| commit | bce3defc8cd2c0c40e40d7b6cfc58159000ded65 (patch) | |
| tree | 294c4de2ec410834416e1c4071e68bed596b8c52 /addons/web/static/src/js/views/abstract_model.js | |
| parent | e83c3e2678500c9bf2c17b4d23ae9a294ebafaa7 (diff) | |
[FIX] web: fix calendar server values parsing
The record data given to fullCalendar to use in the renderEvent
function was not parsed like it is in basic model for example.
As a result, date(time) fields were string rather than moment
objects, which was triggering the crash that started this commit.
Diffstat (limited to 'addons/web/static/src/js/views/abstract_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/abstract_model.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/abstract_model.js b/addons/web/static/src/js/views/abstract_model.js index 27d13a12b06..4ea6b217e65 100644 --- a/addons/web/static/src/js/views/abstract_model.js +++ b/addons/web/static/src/js/views/abstract_model.js @@ -15,6 +15,7 @@ odoo.define('web.AbstractModel', function (require) { */ var Class = require('web.Class'); +var fieldUtils = require('web.field_utils'); var mixins = require('web.mixins'); var ServicesMixin = require('web.ServicesMixin'); @@ -63,6 +64,30 @@ var AbstractModel = Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { reload: function (params) { return $.when(); }, + /** + * Processes date(time) and selection field values sent by the server. + * Converts data(time) values to moment instances. + * Converts false values of selection fields to 0 if 0 is a valid key, + * because the server doesn't make a distinction between false and 0, and + * always sends false when value is 0. + * + * @param {Object} field the field description + * @param {*} value + * @returns {*} the processed value + */ + _parseServerValue: function (field, value) { + if (field.type === 'date' || field.type === 'datetime') { + // process date(time): convert into a moment instance + value = fieldUtils.parse[field.type](value, field, {isUTC: true}); + } else if (field.type === 'selection' && value === false) { + // process selection: convert false to 0, if 0 is a valid key + var hasKey0 = _.find(field.selection, function (option) { + return option[0] === 0; + }); + value = hasKey0 ? 0 : value; + } + return value; + }, }); return AbstractModel; |
