diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-04-22 13:57:49 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-04-24 10:12:47 +0200 |
| commit | 1561165fe25c33ea773d76710b2c94e7d71968d4 (patch) | |
| tree | a3536fbcd16547e7eee5b6f76e3b56b40f41e26f /addons/web/static/src | |
| parent | 329c2ded24af600feaf6d013e6ad71ba41126665 (diff) | |
[FIX] web: properly format dates in context
When evaluating a context, we need to use the server format for dates,
because the context will ultimately be sent do the server. Also, moment
objects are not known by pyeval, so they simply cause a crash (for
example, see bank statements form view, edit it, click on 'add an item')
With this commit, we make sure that the evaluation context is correct,
with respect to dates (we use the toJSON method, because that is the way
we get the server compatible date)
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/core/context.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/addons/web/static/src/js/core/context.js b/addons/web/static/src/js/core/context.js index fe271afd244..53254bd718a 100644 --- a/addons/web/static/src/js/core/context.js +++ b/addons/web/static/src/js/core/context.js @@ -23,13 +23,29 @@ var Context = Class.extend({ this.__contexts.push(context); return this; }, - set_eval_context: function (eval_context) { - this.__eval_context = eval_context; - return this; - }, eval: function () { return pyeval.eval('context', this); }, + /** + * Set the evaluation context to be used when we actually eval. + * + * @param {Object} evalContext + * @returns {Context} + */ + set_eval_context: function (evalContext) { + // a special case needs to be done for moment objects. Dates are + // internally represented by a moment object, but they need to be + // converted to the server format before being sent. We call the toJSON + // method, because it returns the date with the format required by the + // server + for (var key in evalContext) { + if (evalContext[key] instanceof moment) { + evalContext[key] = evalContext[key].toJSON(); + } + } + this.__eval_context = evalContext; + return this; + }, }); return Context; |
