diff options
| author | Jérémy Hennecart <jeh@odoo.com> | 2020-07-22 07:31:08 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-08-18 08:56:48 +0000 |
| commit | 2c21301d314e4fd7c16ac88162786c096e9d80bd (patch) | |
| tree | 4fecb868d6327748682b7fc3bf2c2352c7d74733 /addons/web/static/src | |
| parent | 29b44207c9d59473c9532713aed20b01f6a36d0e (diff) | |
[IMP] web: manage invisible fields in graph and pivot view
PURPOSE
Be able to remove some measures from graph / pivot views. Currently fields
are automatically added but some of them make no sense.
SPECIFICATIONS
Add the possibility to not display some fields in the measures dropdown for
the graph and pivot views.
When a field is not displayed in the measures of a pivot views we remove them
also from the list of groupable fields.
LINKS
Task ID-2288381
Community PR #54774
Enterprise PR odoo/enterprise#11970
Upgrade PR odoo/upgrade#1519
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/views/graph/graph_view.js | 16 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/pivot/pivot_view.js | 12 |
2 files changed, 23 insertions, 5 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 5293409cb8b..759817c898f 100644 --- a/addons/web/static/src/js/views/graph/graph_view.js +++ b/addons/web/static/src/js/views/graph/graph_view.js @@ -43,7 +43,7 @@ var GraphView = AbstractView.extend({ let measure; const measures = {}; const measureStrings = {}; - const groupBys = []; + let groupBys = []; const groupableFields = {}; this.fields.__count__ = { string: _t("Count"), type: 'integer' }; @@ -100,6 +100,20 @@ var GraphView = AbstractView.extend({ } } + // Remove invisible fields from the measures + this.arch.children.forEach(field => { + let fieldName = field.attrs.name; + if (field.attrs.invisible && py.eval(field.attrs.invisible)) { + groupBys = groupBys.filter(groupBy => groupBy !== fieldName); + if (fieldName in groupableFields) { + delete groupableFields[fieldName]; + } + if (!additionalMeasures.includes(fieldName)) { + delete measures[fieldName]; + } + } + }); + const sortedMeasures = Object.values(measures).sort((a, b) => { const descA = a.description.toLowerCase(); const descB = b.description.toLowerCase(); diff --git a/addons/web/static/src/js/views/pivot/pivot_view.js b/addons/web/static/src/js/views/pivot/pivot_view.js index 7c021d6e3c0..ea3ab9c7442 100644 --- a/addons/web/static/src/js/views/pivot/pivot_view.js +++ b/addons/web/static/src/js/views/pivot/pivot_view.js @@ -67,11 +67,15 @@ odoo.define('web.PivotView', function (require) { this.arch.children.forEach(field => { let name = field.attrs.name; - - // Remove invisible fields from the measures + // Remove invisible fields from the measures if not in additionalMeasures if (field.attrs.invisible && py.eval(field.attrs.invisible)) { - delete measures[name]; - return; + if (name in groupableFields) { + delete groupableFields[name]; + } + if (!additionalMeasures.includes(name)) { + delete measures[name]; + return; + } } if (field.attrs.interval) { name += ':' + field.attrs.interval; |
