I want to multiply the valuation rate with the quantity in the child table of Sales Invoice. I tried the following script but the output is nothing:
frappe.ui.form.on("Sales Invoice Item", "qty", function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, "cost_amount", d.qty * d.valuation_rate);
var total = 0;
frm.doc.quotesection.forEach(function(d) { total += d.cost_amount; });
frm.set_value('total_cost', total);
refresh_field("total_cost");
});
Here total_cost is the field in Sales Invoice which will calculate the qty * valuation rate in the child table. The valuation_rate field is filed in the child table. I need to find the total for the qty*rate and for all rows as they are update and put all the data in the total_cost field.
What i want is to first calculate the amount of cost as in cost*qty and put in the field cost_amount in the child table Sales Invoice Item , then sum up the cost_amount in each row and put in total_cost in the Sales Invoice table.
The once you shared is just to sum up the quantity and give the total quantity .
i run the following code, still the field is empty. My goal is : first calculate the amount of cost as in cost*qty and put in the field cost_amount in the child table Sales Invoice Item , then sum up the cost_amount in each row and put in total_cost in the Sales Invoice table.
frappe.ui.form.on(“Sales Invoice”, “qty”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “cost_amount”, d.qty * d.valuation_rate);
var total = 0;
frm.doc.items.forEach(function(d) { total += d.cost_amount; });
Did you added valuation rate field in the sales invoice item? Because standard doctype don’t have this field.
If you have added this as a custom field then it seems that the system not set the value in the field. Before above method you have to write the code to set the valuation rate of an item in the field valuation rate