diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-08-22 08:45:52 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-08-24 07:20:22 +0200 |
| commit | acb9d60d944f21606ee4a9decb752a7a24c65d9d (patch) | |
| tree | 06e1cfa05d4845d7c94e8e07df06edaf0c370a4e /addons/web/static | |
| parent | db0810dc6e063ff1b3d6dd50f13844ed812d4f1e (diff) | |
[FIX] web: Pivot: handle __count__ measure
The former implementation of the Pivot view used __count__ as
magic field to display the number of records in groups. However,
in filters defined in xml, __count is used instead of __count__,
so it crashed when such filters were activated.
With the new views, we made those filters work by using __count.
However, if a user saved filters using __count__ at that time as
favorite, activating them in the new views produces a crash as
well.
This rev. adds a compatibility layer to ensure that the pivot
view handles both __count__ and __count measures uniformly.
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/views/pivot/pivot_model.js | 13 | ||||
| -rw-r--r-- | addons/web/static/tests/views/pivot_tests.js | 29 |
2 files changed, 41 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js index d74af7fee22..13275926c02 100644 --- a/addons/web/static/src/js/views/pivot/pivot_model.js +++ b/addons/web/static/src/js/views/pivot/pivot_model.js @@ -222,6 +222,17 @@ var PivotModel = AbstractModel.extend({ * @returns {Deferred} */ load: function (params) { + // In the preview implementation of the pivot view (a.k.a. version 2), + // the virtual field used to display the number of records was named + // __count__, whereas __count is actually the one used in xml. So + // basically, activating a filter specifying __count as measures crashed. + // Unfortunately, as __count__ was used in the JS, all filters saved as + // favorite at that time were saved with __count__, and not __count. + // So in order the make them still work with the new implementation, we + // simply rename __count__ into __count at this unique entry point. + var measures = _.map(params.measures, function (measure) { + return measure === '__count__' ? '__count' : measure; + }); this.initialDomain = params.domain; this.initialRowGroupBys = params.rowGroupBys; this.fields = params.fields; @@ -231,7 +242,7 @@ var PivotModel = AbstractModel.extend({ context: _.extend({}, session.user_context, params.context), groupedBy: params.groupedBy, colGroupBys: params.colGroupBys, - measures: params.measures, + measures: measures, sorted_column: {}, }; this.defaultGroupedBy = params.groupedBy; diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 267437845b0..eb2b18f7d71 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -859,4 +859,33 @@ QUnit.module('Views', { pivot.destroy(); }); + QUnit.test('pivot still handles __count__ measure', function (assert) { + // for retro-compatibility reasons, the pivot view still handles + // '__count__' measure. + assert.expect(2); + + var pivot = createView({ + View: PivotView, + model: "partner", + data: this.data, + arch: '<pivot></pivot>', + mockRPC: function (route, args) { + if (args.method === 'read_group') { + assert.deepEqual(args.kwargs.fields, ['__count'], + "should make a read_group with field __count"); + } + return this._super(route, args); + }, + viewOptions: { + context: { + pivot_measures: ['__count__'], + }, + }, + }); + + var $countMeasure = pivot.$buttons.find('li[data-field=__count]'); + assert.ok($countMeasure.hasClass('selected'), "The count measure should be activated"); + + pivot.destroy(); + }); });}); |
