diff options
| author | Francois Volral <fvo@odoo.com> | 2018-07-09 14:58:05 +0200 |
|---|---|---|
| committer | Francois Volral <fvo@odoo.com> | 2018-08-10 17:21:17 +0200 |
| commit | 3d2ca8104e46721b5db319a2aeb0ee971cb009d7 (patch) | |
| tree | 4821f6c432449f84267374b925fe9be06efa7119 /addons/web/static/src/js/views/graph/graph_model.js | |
| parent | 4a40db209706a5adae879a2b4349f873b336ccb9 (diff) | |
[IMP] web: Handle date interval in graph charts
This commit only applies for chart grouped on date or datetime fields.
In that case:
- Line Charts : fill missing groups and doesn't display undefined values.
- Bar Charts : doesn't fill missing groups but display undefined values.
- Pie Charts : doesn't fill missing groups but display undefined values.
This commit is part of task #1835644
Diffstat (limited to 'addons/web/static/src/js/views/graph/graph_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/graph/graph_model.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/addons/web/static/src/js/views/graph/graph_model.js b/addons/web/static/src/js/views/graph/graph_model.js index 3c1d26ea252..6d50dd8c269 100644 --- a/addons/web/static/src/js/views/graph/graph_model.js +++ b/addons/web/static/src/js/views/graph/graph_model.js @@ -135,6 +135,7 @@ return AbstractModel.extend({ var fields = _.map(groupedBy, function (groupBy) { return groupBy.split(':')[0]; }); + if (this.chart.measure !== '__count__') { if (this.fields[this.chart.measure].type === 'many2one') { fields = fields.concat(this.chart.measure + ":count_distinct"); @@ -143,10 +144,12 @@ return AbstractModel.extend({ fields = fields.concat(this.chart.measure); } } + + var context = _.extend({fill_temporal: true}, this.chart.context); return this._rpc({ model: this.modelName, method: 'read_group', - context: this.chart.context, + context: context, domain: this.chart.domain, fields: fields, groupBy: groupedBy, @@ -176,7 +179,8 @@ return AbstractModel.extend({ labels = _.map(this.chart.groupedBy, function (field) { return self._sanitizeValue(data_pt[field], field); }); - var value = is_count ? data_pt.__count || data_pt[this.chart.groupedBy[0]+'_count'] : data_pt[this.chart.measure]; + var count = data_pt.__count || data_pt[this.chart.groupedBy[0]+'_count'] || 0; + var value = is_count ? count : data_pt[this.chart.measure]; if (value instanceof Array) { // when a many2one field is used as a measure AND as a grouped // field, bad things happen. The server will only return the @@ -188,8 +192,9 @@ return AbstractModel.extend({ value = 1; } this.chart.data.push({ + count: count, value: value, - labels: labels + labels: labels, }); } }, @@ -203,7 +208,9 @@ return AbstractModel.extend({ */ _sanitizeValue: function (value, field) { var fieldName = field.split(':')[0]; - if (value === false && this.fields[fieldName].type !== 'boolean') return _t("Undefined"); + if (value === false && this.fields[fieldName].type !== 'boolean') { + return undefined; + } if (value instanceof Array) return value[1]; if (field && (this.fields[fieldName].type === 'selection')) { var selected = _.where(this.fields[fieldName].selection, {0: value})[0]; |
