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 e0b232b6310..251fa10200d 100644 --- a/addons/web/static/src/js/views/pivot/pivot_view.js +++ b/addons/web/static/src/js/views/pivot/pivot_view.js @@ -33,6 +33,7 @@ var PivotView = AbstractView.extend({ * @param {Object} params */ init: function (viewInfo, params) { + var self = this; this._super.apply(this, arguments); var self = this; @@ -71,8 +72,9 @@ var PivotView = AbstractView.extend({ // the measure should be allowed. However, be careful if you define // a measure in your pivot view: non stored functional fields will // probably not work (their aggregate will always be 0). - if (field.type === 'measure' && !(field.name in measures)) { - measures[field.name] = field; + + if (field.attrs.type === 'measure' && !(field.attrs.name in measures)) { + measures[field.attrs.name] = self.fields[field.attrs.name]; } if (field.attrs.type === 'measure' || 'operator' in field.attrs) { activeMeasures.push(name); @@ -100,6 +102,7 @@ var PivotView = AbstractView.extend({ this.controllerParams.groupableFields = groupableFields; // retrieve form and list view ids from the action to open those views // when a data cell of the pivot view is clicked + this.controllerParams.views = [ _findView(params.action && params.action.views, 'list'), _findView(params.action && params.action.views, 'form'), diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 26733a5edca..a1d9e1fae1f 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -20,6 +20,7 @@ QUnit.module('Views', { other_product_id: {string: "Other Product", type: "many2one", relation: 'product', store: true}, non_stored_m2o: {string: "Non Stored M2O", type: "many2one", relation: 'product'}, customer: {string: "Customer", type: "many2one", relation: 'customer', store: true}, + computed_field: {string: "Computed and not stored", compute:true}, }, records: [ { @@ -29,6 +30,7 @@ QUnit.module('Views', { date: '2016-12-14', product_id: 37, customer: 1, + computed_field: 19, }, { id: 2, foo: 1, @@ -36,6 +38,7 @@ QUnit.module('Views', { date: '2016-10-26', product_id: 41, customer: 2, + computed_field: 23, }, { id: 3, foo: 17, @@ -43,12 +46,14 @@ QUnit.module('Views', { date: '2016-12-15', product_id: 41, customer: 2, + computed_field: 26, }, {id: 4, foo: 2, bar: false, date: '2016-04-11', product_id: 41, customer: 1, + computed_field: 19, }, ] }, @@ -122,6 +127,22 @@ QUnit.module('Views', { pivot.destroy(); }); + QUnit.test('pivot view add computed fields explicitly defined as measure', function (assert) { + assert.expect(1); + + var pivot = createView({ + View: PivotView, + model: "partner", + data: this.data, + arch: '' + + '' + + '', + }); + + assert.ok(pivot.measures.computed_field, "measures contains the field 'computed_field'"); + pivot.destroy(); + }); + QUnit.test('clicking on a cell triggers a do_action', function (assert) { assert.expect(2);