mirror of https://github.com/OCA/web.git
[FIX] web_pivot_computed_measure: Use config instead of perform loadData
parent
649e206c86
commit
24a3669a83
|
@ -73,6 +73,11 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
* @returns a promise
|
* @returns a promise
|
||||||
*/
|
*/
|
||||||
_createVirtualMeasure(cmDef, fields) {
|
_createVirtualMeasure(cmDef, fields) {
|
||||||
|
this._createVirtualField(cmDef, fields);
|
||||||
|
// Activate computed field
|
||||||
|
return this.toggleMeasure(cmDef.id);
|
||||||
|
},
|
||||||
|
_createVirtualField(cmDef, fields, config) {
|
||||||
const arrFields = fields || this.metaData.fields;
|
const arrFields = fields || this.metaData.fields;
|
||||||
// This is a minimal 'fake' field info
|
// This is a minimal 'fake' field info
|
||||||
arrFields[cmDef.id] = {
|
arrFields[cmDef.id] = {
|
||||||
|
@ -88,11 +93,9 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
// Operator used for group the measure added.
|
// Operator used for group the measure added.
|
||||||
group_operator: "sum",
|
group_operator: "sum",
|
||||||
};
|
};
|
||||||
this.metaData.measures[cmDef.id] = arrFields[cmDef.id];
|
const metaData = (config && config.metaData) || this.metaData;
|
||||||
// Activate computed field
|
metaData.measures[cmDef.id] = arrFields[cmDef.id];
|
||||||
return this.toggleMeasure(cmDef.id);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Active the measures related to the 'fake' field
|
* Active the measures related to the 'fake' field
|
||||||
*
|
*
|
||||||
|
@ -124,8 +127,12 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
* @private
|
* @private
|
||||||
* @param {String} field
|
* @param {String} field
|
||||||
*/
|
*/
|
||||||
_isMeasureEnabled(field) {
|
_isMeasureEnabled(field, config) {
|
||||||
return _.contains(this.metaData.activeMeasures, field);
|
const activeMeasures =
|
||||||
|
(config && config.metaData.activeMeasures) ||
|
||||||
|
this.metaData.activeMeasures ||
|
||||||
|
[];
|
||||||
|
return _.contains(activeMeasures, field);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,9 +141,9 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} subGroupData
|
* @param {Object} subGroupData
|
||||||
*/
|
*/
|
||||||
_fillComputedMeasuresData(subGroupData) {
|
_fillComputedMeasuresData(subGroupData, config) {
|
||||||
for (const cm of this._computed_measures) {
|
for (const cm of this._computed_measures) {
|
||||||
if (!this._isMeasureEnabled(cm.id)) continue;
|
if (!this._isMeasureEnabled(cm.id, config)) continue;
|
||||||
if (subGroupData.__count === 0) {
|
if (subGroupData.__count === 0) {
|
||||||
subGroupData[cm.id] = false;
|
subGroupData[cm.id] = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,10 +158,10 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_prepareData(group, groupSubdivisions) {
|
_prepareData(group, groupSubdivisions, config) {
|
||||||
for (const groupSubdivision of groupSubdivisions) {
|
for (const groupSubdivision of groupSubdivisions) {
|
||||||
for (const subGroup of groupSubdivision.subGroups) {
|
for (const subGroup of groupSubdivision.subGroups) {
|
||||||
this._fillComputedMeasuresData(subGroup);
|
this._fillComputedMeasuresData(subGroup, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
@ -243,6 +250,7 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
*/
|
*/
|
||||||
async load(searchParams) {
|
async load(searchParams) {
|
||||||
var _super = this._super.bind(this);
|
var _super = this._super.bind(this);
|
||||||
|
var config = {metaData: this.metaData, data: this.data};
|
||||||
if (!this.metaData.measures) {
|
if (!this.metaData.measures) {
|
||||||
const metaData = this._buildMetaData();
|
const metaData = this._buildMetaData();
|
||||||
metaData.measures = computeReportMeasures(
|
metaData.measures = computeReportMeasures(
|
||||||
|
@ -251,8 +259,7 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
metaData.activeMeasures,
|
metaData.activeMeasures,
|
||||||
metaData.additionalMeasures
|
metaData.additionalMeasures
|
||||||
);
|
);
|
||||||
const config = {metaData, data: this.data};
|
config = {metaData, data: this.data};
|
||||||
await this._loadData(config);
|
|
||||||
}
|
}
|
||||||
if ("context" in searchParams) {
|
if ("context" in searchParams) {
|
||||||
this._computed_measures =
|
this._computed_measures =
|
||||||
|
@ -261,10 +268,10 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
[];
|
[];
|
||||||
}
|
}
|
||||||
for (const cmDef of this._computed_measures) {
|
for (const cmDef of this._computed_measures) {
|
||||||
if (this._isMeasureEnabled(cmDef.id)) {
|
if (this._isMeasureEnabled(cmDef.id, config)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await this._createVirtualMeasure(cmDef);
|
await this._createVirtualField(cmDef, undefined, config);
|
||||||
}
|
}
|
||||||
const fieldNames = Object.keys(this.metaData.fields);
|
const fieldNames = Object.keys(this.metaData.fields);
|
||||||
for (const fieldName of fieldNames) {
|
for (const fieldName of fieldNames) {
|
||||||
|
@ -280,10 +287,6 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
this.metaData.activeMeasures,
|
this.metaData.activeMeasures,
|
||||||
fieldName
|
fieldName
|
||||||
);
|
);
|
||||||
const config = {metaData: this.metaData, data: this.data};
|
|
||||||
this._loadData(config).then(() => {
|
|
||||||
this.notify();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue