forked from Techsystech/web
[FIX] web_pivot_computed_measure: Use js eval to avoid different types operation error
parent
0638195c11
commit
148495e6dc
|
@ -0,0 +1,27 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
/* Copyright 2022 Tecnativa - Carlos Roca
|
||||||
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to eval text for a given object
|
||||||
|
*
|
||||||
|
* @param {String} text
|
||||||
|
* @param {Object} vals
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
export const evalOperation = (text, vals) => {
|
||||||
|
for (const variable in vals) {
|
||||||
|
if (vals.hasOwnProperty(variable)) {
|
||||||
|
const regex = new RegExp(variable, "g");
|
||||||
|
text = text.replace(regex, vals[variable]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line no-eval
|
||||||
|
const res = eval(text);
|
||||||
|
return res;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error trying to eval operation:", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
|
@ -6,6 +6,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";
|
import {computeReportMeasures} from "@web/views/helpers/utils";
|
||||||
|
import {evalOperation} from "../helpers/utils.esm";
|
||||||
|
|
||||||
patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
/**
|
/**
|
||||||
|
@ -148,7 +149,7 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||||
subGroupData[cm.id] = false;
|
subGroupData[cm.id] = false;
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
subGroupData[cm.id] = py.eval(cm.operation, subGroupData);
|
subGroupData[cm.id] = evalOperation(cm.operation, subGroupData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue