summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/graph
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-04-09 14:32:37 +0200
committerGéry Debongnie <ged@odoo.com>2018-04-10 17:41:12 +0200
commit8dbc1d95c36b18398c7284eddda2fe48842a8904 (patch)
tree35c0de6d39b5ecbcd1c77437c5408fa4f8b6a849 /addons/web/static/src/js/views/graph
parent36b4468d15bf96de097cfc3d7e2d5f99febb984b (diff)
[IMP] web: many2one as measure in graph & pivot only when desirable
With this commit, the fields many2one are not always measures in pivot and graph views. By default, they are *not* measures. In order to have them as measures, we should pass `additionalMeasures` as a param to any of the views, which contains a list of fields to consider as measures. example: Suppose a model with the following fields: - `product_id` (many2one) - `categ_id` (many2one) - `sold` (float) By default, only the field `sold` is a measure in a graph or pivot view. In order to pass `product_id` as a measure of a graph view, you should instantiate this view as follow: `` var viewInfo = /* ... */; var params = { additionalMeasures = ['product_id'], }; var graph = new GraphView(viewInfo, params); `` An exception to the rule above is when the many2one field is of type `measure` in the arch: this field is set as the default measure of the view, therefore it is implicitly added as an additional measure.
Diffstat (limited to 'addons/web/static/src/js/views/graph')
-rw-r--r--addons/web/static/src/js/views/graph/graph_view.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/addons/web/static/src/js/views/graph/graph_view.js b/addons/web/static/src/js/views/graph/graph_view.js
index 8cfe2dc0272..54ff6642b15 100644
--- a/addons/web/static/src/js/views/graph/graph_view.js
+++ b/addons/web/static/src/js/views/graph/graph_view.js
@@ -36,12 +36,15 @@ var GraphView = AbstractView.extend({
/**
* @override
*/
- init: function () {
+ init: function (viewInfo, params) {
this._super.apply(this, arguments);
+ var self = this;
var measure;
var groupBys = [];
+ var measures = {__count__: {string: _t("Count"), type: "integer"}};
this.fields.__count__ = {string: _t("Count"), type: "integer"};
+
this.arch.children.forEach(function (field) {
var name = field.attrs.name;
if (field.attrs.interval) {
@@ -49,16 +52,17 @@ var GraphView = AbstractView.extend({
}
if (field.attrs.type === 'measure') {
measure = name;
+ measures[name] = self.fields[name];
} else {
groupBys.push(name);
}
});
- var measures = {__count__: {string: _t("Count"), type: "integer"}};
_.each(this.fields, function (field, name) {
if (name !== 'id' && field.store === true) {
- if (field.type === 'integer' || field.type === 'float' || field.type === 'monetary' || field.type === 'many2one') {
- measures[name] = field;
+ if (_.contains(['integer', 'float', 'monetary'], field.type) ||
+ _.contains(params.additionalMeasures, name)) {
+ measures[name] = field;
}
}
});