[FIX] web_pivot_computed_measure: Error when using filter created with favorites

pull/2755/head
Carlos Roca 2023-05-09 08:31:42 +02:00
parent 56a923943d
commit c743df7d01
3 changed files with 64 additions and 2 deletions

View File

@ -3,7 +3,7 @@
{
"name": "Web Pivot Computed Measure",
"category": "web",
"version": "15.0.1.0.0",
"version": "15.0.1.0.1",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/web",

View File

@ -135,7 +135,7 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
*/
_fillComputedMeasuresData(subGroupData) {
for (const cm of this._computed_measures) {
if (!this._isMeasureEnabled(cm.id)) return;
if (!this._isMeasureEnabled(cm.id)) continue;
if (subGroupData.__count === 0) {
subGroupData[cm.id] = false;
} else {
@ -235,4 +235,46 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
}
return this._super(...arguments);
},
/**
* Load the measures added to selected favorite filters
*
* @override
*/
async load(searchParams) {
var _super = this._super.bind(this);
if ("context" in searchParams) {
this._computed_measures =
searchParams.context.pivot_computed_measures ||
searchParams.computed_measures ||
[];
}
for (const cmDef of this._computed_measures) {
if (this._isMeasureEnabled(cmDef.id)) {
continue;
}
await this._createVirtualMeasure(cmDef);
}
const fieldNames = Object.keys(this.metaData.fields);
for (const fieldName of fieldNames) {
const field = this.metaData.fields[fieldName];
if (field.__computed_id) {
const cm = _.find(this._computed_measures, {
id: field.__computed_id,
});
if (!cm) {
delete this.metaData.fields[fieldName];
delete this.metaData.measures[fieldName];
this.metaData.activeMeasures = _.without(
this.metaData.activeMeasures,
fieldName
);
const config = {metaData: this.metaData, data: this.data};
this._loadData(config).then(() => {
this.notify();
});
}
}
}
return _super(...arguments);
},
});

View File

@ -0,0 +1,20 @@
/** @odoo-module **/
/* Copyright 2022 Tecnativa - Carlos Roca
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
import {PivotView} from "@web/views/pivot/pivot_view";
import {patch} from "web.utils";
patch(PivotView.prototype, "web_pivot_computed_measure.PivotView", {
/**
* Add computed_measures to context key to avoid loosing info when saving the
* filter to favorites.
*
* @override
*/
getContext() {
var res = this._super(...arguments);
res.pivot_computed_measures = this.model._computed_measures;
return res;
},
});