[IMP] web: allow usage of computed unstored fields in pivot views

This commit is contained in:
Vincent Schippefilt
2018-05-15 14:55:00 +02:00
committed by qdp-odoo
parent 32c6d129ca
commit 09125f78c3
2 changed files with 26 additions and 2 deletions
@@ -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'),
@@ -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: '<pivot>' +
'<field name="computed_field" type="measure"/>' +
'</pivot>',
});
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);