Hey everyone,
Can’t figure what is wrong here?
I am trying to calculate the dish price as per quantity of the produce used.
two problem here:
- When hitting “ud_price” button, without the
alert("updated");
line, the price is 0. - My computer runs the VM where the frappe is installed. On a colleague machine, the result is always 0.
frappe.ui.form.on('Dish', {
refresh(frm) {
cur_frm.cscript.ud_price = function(doc) {
var material;
var price = 0;
var materialType;
var total_price = 0;
var priceDataSource;
var recipeTable = frm.doc.recipes;
var qty;
$.each(recipeTable, function(index, row){
material = row.cat_num;
materialType = "Produce";
frappe.db.get_value(materialType,material,'var_price')
.then(r => {
qty = row.var_quant / 100;
price = r.message.var_price;
total_price = total_price + price * qty;
});
});`
alert("updated");
frm.set_value('var_price',total_price);
};
}
});
Any ideas?