Can we also use this formula to calculate total quantity of items for Purchase orders ? I tried to do so by replacing “sales invoice” by “purchase order” but it didn’t work.
Yes, you can use the same function replacing the doctype name. Please ensure that you are using proper case while replacing doctype name, it should be “Purchase Order Item”. And in Custom Script, select doctype as “Purchase Order”.
Why are you setting the total_qty in UOM field? You should add a custom field for “Total Qty” in Purchase Order form and then set the total qty in that field.
I have added a float custom field for “Total Qty” in Purchase Order form and created a custom script as below for purchase order. Is it what you meant by setting the total qty in Purchase order ? I feel it is maybe because my custom script is not linked to my custom field. How can I link both together ?
frappe.ui.form.on(“Purchase Order Item”, “qty”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_qty = 0;
$.each(frm.doc.items || [], function(i, d) {
total_qty += flt(d.qty);
});
frm.set_value(“total_qty” , total_qty);
});
It should work. Just check that in which field you want to set the total qty. Is the fieldname of that field “total_qty”? Check you custom field record.
Thank you for help. I made a mistake in my text above. I was thinking about delivery note and delivery note item. I modified your code. Is this corect + caould you tell me where to put this code because this is first time i use script. I suppose in DN custom field (broj vaucera)
He don’t copy value from DN while inserting in SI item but (only first row). but at the end i go back in DN field and update value. This also helps me a lot. Thanks once more.