mirror of https://github.com/OCA/web.git
[FIX] web_pivot_computed_measure: Error when using filter created with favorites
parent
9533a8fa8b
commit
e75e9b23bc
|
@ -3,7 +3,7 @@
|
||||||
{
|
{
|
||||||
"name": "Web Pivot Computed Measure",
|
"name": "Web Pivot Computed Measure",
|
||||||
"category": "web",
|
"category": "web",
|
||||||
"version": "15.0.1.0.0",
|
"version": "15.0.1.0.1",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
|
|
|
@ -135,7 +135,7 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
*/
|
*/
|
||||||
_fillComputedMeasuresData(subGroupData) {
|
_fillComputedMeasuresData(subGroupData) {
|
||||||
for (const cm of this._computed_measures) {
|
for (const cm of this._computed_measures) {
|
||||||
if (!this._isMeasureEnabled(cm.id)) return;
|
if (!this._isMeasureEnabled(cm.id)) continue;
|
||||||
if (subGroupData.__count === 0) {
|
if (subGroupData.__count === 0) {
|
||||||
subGroupData[cm.id] = false;
|
subGroupData[cm.id] = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -235,4 +235,46 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
}
|
}
|
||||||
return this._super(...arguments);
|
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);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue