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; diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 6e0fc199b6c..11433bff92c 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1898,6 +1898,42 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('one2many list, editable, with a date in the context', function (assert) { + assert.expect(1); + + this.data.partner.records[0].p = [2]; + this.data.partner.records[1].product_id = 37; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 2, + mockRPC: function (route, args) { + if (args.method === 'default_get') { + assert.strictEqual(args.kwargs.context.date, '2017-01-25', + "should have properly evaluated date key in context"); + } + return this._super.apply(this, arguments); + }, + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_form_field_x2many_list_row_add a').click(); + + form.destroy(); + }); + QUnit.test('one2many list edition, some basic functionality', function (assert) { assert.expect(3);