diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-02-23 14:08:33 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 3c0190d0a6c0d5ccc130fd9b685681fa9bac1de3 (patch) | |
| tree | 9dda80c321a23ce122b092fb8b62a4f3e44bd271 /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | cce579434b172eeb63049a471334e18df15fa401 (diff) | |
[IMP] web: use moment object instead of string for date
Before this commit, the odoo web client used strings to represent dates.
Now, the date is parsed into a moment object when the value is read from the
server side. The widget formats the object to display the value. When the
widget value changes, the value is parsed to a moment object. The value is
automatically formatted to server value in ajax calls (toJSON method).
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 | 15 |
1 files changed, 14 insertions, 1 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 2028127c202..2f6c3849b86 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -83,6 +83,7 @@ var Context = require('web.Context'); var data = require('web.data'); // TODO: remove dependency to data.js var pyeval = require('web.pyeval'); var session = require('web.session'); +var field_utils = require('web.field_utils'); var x2ManyCommands = { // (0, _, {values}) @@ -536,6 +537,12 @@ var Model = AbstractModel.extend({ _.each(_.keys(many2ones), function (name) { defs.push(self._fetchNameGets(x2manyList, name)); }); + } else if (field.type === 'date') { + // process date: convert into Date object + record._changes[name] = field_utils.parse_date(result[name]); + } else if (field.type === 'datetime') { + // process datetime: convert into Date object + record._changes[name] = field_utils.parse_datetime(result[name]); } else { record._changes[name] = result[name]; } @@ -1252,11 +1259,11 @@ var Model = AbstractModel.extend({ record.data = _.extend({}, record.data, result); return self._postprocess(record); }).then(function (record) { - // process many2one: split [id, nameget] and create corresponding record _.each(fieldNames, function (name) { var field = record.fields[name]; var val = record.data[name]; if (field.type === 'many2one') { + // process many2one: split [id, nameget] and create corresponding record if (val !== false) { // the many2one value is of the form [id, display_name] var r = self._makeDataPoint({ @@ -1271,6 +1278,12 @@ var Model = AbstractModel.extend({ // no value for the many2one record.data[name] = false; } + } else if (field.type === 'date') { + // process data: convert into Date object + record.data[name] = field_utils.parse_date(val); + } else if (field.type === 'datetime') { + // process datetime: convert into Date object + record.data[name] = field_utils.parse_datetime(val); } }); }).then(function () { |
