1

I want to use one of the NPM package called "safe-eval" (https://www.npmjs.com/package/safe-eval) inside of Odoo js function.

I have installed the package in Node.js but I cannot use it inside Odoo JS.

I tried to import it in my JS file but this seems not working.

var safeEval = require("safe-eval");

This is my function

_compute_all: function(tax, base_amount, quantity) {
    if (tax.amount_type === 'code') {

        var product = {standard_price:20};
        var code = 'result = (price_unit - product.standard_price) * 0.25';
        var context = {
            price_unit: 100,
            product: product,
        };
        var evaluated = safeEval(code, context);
        return evaluated;
    }
 },

When I run this code it cannot find the 'safe-eval' dependancy. It gives an missing dependancy error.

My system is running on Windows in case if you need to know.

Thank You.

0 Answers0