diff --git a/addons/web/static/src/js/views/graph/graph_controller.js b/addons/web/static/src/js/views/graph/graph_controller.js
index e9f933023b1..e7f25c23fdd 100644
--- a/addons/web/static/src/js/views/graph/graph_controller.js
+++ b/addons/web/static/src/js/views/graph/graph_controller.js
@@ -88,7 +88,7 @@ var GraphController = AbstractController.extend(GroupByMenuInterfaceMixin,{
renderButtons: function ($node) {
if ($node) {
var context = {
- measures: _.pairs(_.omit(this.measures, '__count__')),
+ measures: _.sortBy(_.pairs(_.omit(this.measures, '__count__')), function (x) { return x[0]; }),
};
this.$buttons = $(qweb.render('GraphView.buttons', context));
this.$measureList = this.$buttons.find('.o_graph_measures_list');
diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js
index 5f31c7103c7..f0976c9a8b4 100644
--- a/addons/web/static/src/js/views/pivot/pivot_controller.js
+++ b/addons/web/static/src/js/views/pivot/pivot_controller.js
@@ -102,7 +102,7 @@ var PivotController = AbstractController.extend({
*/
renderButtons: function ($node) {
if ($node) {
- var context = {measures: _.pairs(_.omit(this.measures, '__count'))};
+ var context = {measures: _.sortBy(_.pairs(_.omit(this.measures, '__count')), function(x) { return x[0]; })};
this.$buttons = $(QWeb.render('PivotView.buttons', context));
this.$buttons.click(this._onButtonClick.bind(this));
this.$buttons.find('button').tooltip();
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 251fa10200d..643ee68a498 100644
--- a/addons/web/static/src/js/views/pivot/pivot_view.js
+++ b/addons/web/static/src/js/views/pivot/pivot_view.js
@@ -119,5 +119,3 @@ var PivotView = AbstractView.extend({
return PivotView;
});
-
-
diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js
index 5f7227815c1..60e6680993c 100644
--- a/addons/web/static/tests/views/graph_tests.js
+++ b/addons/web/static/tests/views/graph_tests.js
@@ -622,6 +622,30 @@ QUnit.module('Views', {
assert.ok(true,"should not generate any error");
graph.destroy();
});
+
+ QUnit.test('graph measures should be alphabetically sorted', function (assert) {
+ assert.expect(2);
+
+ var data = this.data;
+ data.foo.fields.bouh = {string: "bouh", type: "integer"};
+
+ var graph = createView({
+ View: GraphView,
+ model: "foo",
+ data: data,
+ arch: '' +
+ '' +
+ '' +
+ '',
+ })
+
+ assert.strictEqual(graph.$buttons.find('.o_graph_measures_list li:first').data('field'), 'bouh',
+ "Bouh should be the first measure");
+ assert.strictEqual(graph.$buttons.find('.o_graph_measures_list li:last').data('field'), '__count__',
+ "Count should be the last measure");
+
+ graph.destroy();
+ });
});
});
diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js
index 4d7358f2574..70eee5b3431 100644
--- a/addons/web/static/tests/views/pivot_tests.js
+++ b/addons/web/static/tests/views/pivot_tests.js
@@ -1178,4 +1178,28 @@ QUnit.module('Views', {
"should have 6 rows");
pivot.destroy();
});
+
+ QUnit.test('pivot measures should be alphabetically sorted', function (assert) {
+ assert.expect(2);
+
+ var data = this.data;
+ data.partner.fields.bouh = {string: "bouh", type: "integer"};
+
+ var pivot = createView({
+ View: PivotView,
+ model: "partner",
+ data: data,
+ arch: '' +
+ '' +
+ '' +
+ '',
+ })
+
+ assert.strictEqual(pivot.$buttons.find('.o_pivot_measures_list li:first').data('field'), 'bouh',
+ "Bouh should be the first measure");
+ assert.strictEqual(pivot.$buttons.find('.o_pivot_measures_list li:last').data('field'), '__count',
+ "Count should be the last measure");
+
+ pivot.destroy();
+ });
});});
diff --git a/doc/reference/views.rst b/doc/reference/views.rst
index 9093bc314c6..f8a87032a0e 100644
--- a/doc/reference/views.rst
+++ b/doc/reference/views.rst
@@ -784,7 +784,7 @@ The only allowed element within a graph view is ``field`` which can have the
following attributes:
``name`` (required)
- the name of a field to use in a graph view. If used for grouping (rather
+ the name of a field to use in the view. If used for grouping (rather
than aggregating)
``type``
@@ -793,10 +793,9 @@ following attributes:
``row`` (default)
groups by the specified field. All graph types support at least one level
- of grouping, some may support more. For pivot views, each group gets its
- own row.
+ of grouping, some may support more.
``col``
- only used by pivot tables, creates column-wise groups
+ authorized in graph views but only used by pivot tables
``measure``
field to aggregate within a group
@@ -805,13 +804,20 @@ following attributes:
``week``, ``month``, ``quarter`` or ``year``) instead of grouping on the
specific datetime (fixed second resolution) or date (fixed day resolution).
+The measures are automatically generated from the model fields; only the
+aggregatable fields are used. Those measures are also alphabetically
+sorted on the string of the field.
+
.. warning::
graph view aggregations are performed on database content, non-stored
function fields can not be used in graph views
+
+.. _reference/views/pivot:
+
Pivots
-------
+======
The pivot view is used to visualize aggregations as a `pivot table`_. Its root
element is ```` which can take the following attributes:
@@ -821,7 +827,37 @@ element is ```` which can take the following attributes:
``display_quantity``
Set to ``true`` to display the Quantity column by default.
-The elements allowed within a pivot view are the same as for the graph view.
+The only allowed element within a pivot view is ``field`` which can have the
+following attributes:
+
+``name`` (required)
+ the name of a field to use in the view. If used for grouping (rather
+ than aggregating)
+
+``type``
+ indicates whether the field should be used as a grouping criteria or as an
+ aggregated value within a group. Possible values are:
+
+ ``row`` (default)
+ groups by the specified field, each group gets its own row.
+ ``col``
+ creates column-wise groups
+ ``measure``
+ field to aggregate within a group
+ ``interval``
+ on date and datetime fields, groups by the specified interval (``day``,
+ ``week``, ``month``, ``quarter`` or ``year``) instead of grouping on the
+ specific datetime (fixed second resolution) or date (fixed day resolution).
+
+The measures are automatically generated from the model fields; only the
+aggregatable fields are used. Those measures are also alphabetically
+sorted on the string of the field.
+
+.. warning::
+
+ like the graph view, the pivot aggregates data on database content
+ which means that non-stored function fields can not be used in pivot views
+
.. _reference/views/kanban: