Hello everyone. I'm adding a function to a spreadsheet but it returns "[object Promise]" instead of result. I don't know how to fix it, please help me.
Code Js:
const CAL_AREA = {
description: _t("Calculate duct area from given dimensions"),
args: [
arg("internal_code (string)", _t("The internal code of duct type.")),
arg("length (number)", _t("Length in mm")),
arg("width (number)", _t("Width in mm")),
arg("height (number)", _t("Height in mm")),
arg("diameter (number)", _t("Diameter in mm")),
arg("radius (number)", _t("Radius in mm")),
],
category: "Odoo",
compute: async function (internal_code, length, width, height, diameter, radius) {
try {
const result = await this.env.services.rpc("/web/dataset/call_kw", {
model: "spreadsheet.mixin",
method: "cal_area",
args: [[]],
kwargs: {
internal_code,
length,
width,
height,
diameter,
radius,
},
});
console.log("result: ", result)
return result;
} catch (error) {
console.error("Error in CAL_AREA:", error);
return 0;
}
},
returns: ["NUMBER"],
};
Code Python:
def _get_product_duct_type(self, internal_code):
product = self.env['product.product'].search([('internal_code', '=', internal_code)], limit=1)
if product:
return product.duct_type
return False
def cal_area(self, internal_code, length, width, height, diameter, radius):
duct_type = self._get_product_duct_type(internal_code)
area = 0.0
if duct_type in ['standard_square', 'cone_fitting', 'square_baffle_fitting', 'z_shaped_duct']:
area = (length + width) * 2 * height / 1000
elif duct_type == 'round_baffle_fitting':
area = (diameter * 3.14 * height) / 1000
elif duct_type == 'square_damper':
area = ((length + width) * 2 * (radius + length / 2) * 3.14 / 2) / 1000000
elif duct_type == 'round_damper':
area = ((diameter * 3.14) * (radius + length / 2) * 3.14 / 2) / 1000000
return area