mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[FIX] web_pivot_computed_measure: Use js eval to avoid different types operation error
This commit is contained in:
27
web_pivot_computed_measure/static/src/helpers/utils.esm.js
Normal file
27
web_pivot_computed_measure/static/src/helpers/utils.esm.js
Normal file
@@ -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 {patch} from "web.utils";
|
||||
import {computeReportMeasures} from "@web/views/helpers/utils";
|
||||
import {evalOperation} from "../helpers/utils.esm";
|
||||
|
||||
patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||
/**
|
||||
@@ -148,7 +149,7 @@ patch(PivotModel.prototype, "web_pivot_computed_measure.PivotModel", {
|
||||
subGroupData[cm.id] = false;
|
||||
} else {
|
||||
// eslint-disable-next-line no-undef
|
||||
subGroupData[cm.id] = py.eval(cm.operation, subGroupData);
|
||||
subGroupData[cm.id] = evalOperation(cm.operation, subGroupData);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user