forked from Techsystech/web
Merge PR #2508 into 15.0
Signed-off-by pedrobaeza15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
commit
cc2bcccd15
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import {PivotModel} from "@web/views/pivot/pivot_model";
|
import {PivotModel} from "@web/views/pivot/pivot_model";
|
||||||
import {patch} from "web.utils";
|
import {patch} from "web.utils";
|
||||||
|
import {computeReportMeasures} from "@web/views/helpers/utils";
|
||||||
|
|
||||||
patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
/**
|
/**
|
||||||
|
@ -72,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] = {
|
||||||
|
@ -87,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
|
||||||
*
|
*
|
||||||
|
@ -123,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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,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 {
|
||||||
|
@ -150,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);
|
||||||
|
@ -242,6 +250,17 @@ 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) {
|
||||||
|
const metaData = this._buildMetaData();
|
||||||
|
metaData.measures = computeReportMeasures(
|
||||||
|
metaData.fields,
|
||||||
|
metaData.fieldAttrs,
|
||||||
|
metaData.activeMeasures,
|
||||||
|
metaData.additionalMeasures
|
||||||
|
);
|
||||||
|
config = {metaData, data: this.data};
|
||||||
|
}
|
||||||
if ("context" in searchParams) {
|
if ("context" in searchParams) {
|
||||||
this._computed_measures =
|
this._computed_measures =
|
||||||
searchParams.context.pivot_computed_measures ||
|
searchParams.context.pivot_computed_measures ||
|
||||||
|
@ -249,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) {
|
||||||
|
@ -268,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();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
/* Copyright 2022 Tecnativa - Carlos Roca
|
||||||
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
||||||
|
|
||||||
|
import {PivotRenderer} from "@web/views/pivot/pivot_renderer";
|
||||||
|
import {patch} from "web.utils";
|
||||||
|
|
||||||
|
patch(PivotRenderer.prototype, "web_pivot_computed_measure.PivotRenderer", {
|
||||||
|
getFormattedValue(cell) {
|
||||||
|
if (cell.value === Infinity) {
|
||||||
|
return "-";
|
||||||
|
}
|
||||||
|
return this._super(...arguments);
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue