From 9009c5375ee0dec0fdf5c6257065066ef5a3f6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 26 May 2017 13:16:01 +0200 Subject: [FIX] web: fix various issues with eval contexts Eval contexts are not easy... They should be different when sent to the server and when evaluated in the web client. In this commit, we fix some small issues: - when evaluated on the web client, x2manys should be a list of ids, when sent to the server, it should be a list of commands - dates should be converted to string - always add current_date in the evaluation context, as a magic key (it was previously only available in row decoration context evaluations) --- .../web/static/src/js/views/basic/basic_model.js | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 85150061075..84ae999ac88 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2098,10 +2098,11 @@ var BasicModel = AbstractModel.extend({ } } return _.extend({ - active_model: element.model, - id: evalContext.id || false, active_id: evalContext.id || false, active_ids: evalContext.id ? [evalContext.id] : [], + active_model: element.model, + current_date: moment().format('YYYY-MM-DD'), + id: evalContext.id || false, }, session.user_context, element.context, evalContext); }, /** @@ -2141,6 +2142,12 @@ var BasicModel = AbstractModel.extend({ context[fieldName] = context[fieldName] || 0; continue; } + if (field.type === 'date' || field.type === 'datetime') { + if (context[fieldName]) { + context[fieldName] = JSON.parse(JSON.stringify(context[fieldName])); + } + continue; + } if (field.type === 'many2one') { relDataPoint = this.localData[context[fieldName]]; context[fieldName] = relDataPoint ? relDataPoint.res_id : false; @@ -2149,16 +2156,22 @@ var BasicModel = AbstractModel.extend({ if (field.type === 'one2many' || field.type === 'many2many') { relDataPoint = this.localData[context[fieldName]]; var relData = relDataPoint._changes || relDataPoint.data; - var commands = _.map(relData, function (id) { - var resID = self.localData[id].res_id; - if (typeof resID === 'string') { - var changes = self._generateChanges(self.localData[id]); - return x2ManyCommands.create(changes); - } else { - return x2ManyCommands.link_to(resID); - } + var ids = _.map(relData, function (id) { + return self.localData[id].res_id; }); - context[fieldName] = commands; + + ids.toJSON = function () { + return _.map(relData, function (id) { + var resID = self.localData[id].res_id; + if (typeof resID === 'string') { + var changes = self._generateChanges(self.localData[id]); + return x2ManyCommands.create(changes); + } else { + return x2ManyCommands.link_to(resID); + } + }); + }; + context[fieldName] = ids; } } -- cgit v1.2.3