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(); + }); });});