diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-05-26 13:16:01 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-05-26 15:02:29 +0200 |
| commit | 9009c5375ee0dec0fdf5c6257065066ef5a3f6f7 (patch) | |
| tree | 4c303d96151374526282e91df2607915a5c568ec /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 0c28dbf969233990eab01c52abd3f214cc299071 (diff) | |
[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)
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 | 35 |
1 files changed, 24 insertions, 11 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 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; } } |
