Net Weight does not display in Sales Invoice form.
It displace after saving but I want onchange of qty.
frappe.ui.form.on("Sales Invoice 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("net_weight", total_qty);
});
Hello Nabinhait!
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.
Thank you !
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”.
Hi Nabinhait,
I have tried the following script by changing the field type to float, table and data but none work. Is my script wrong ?
Thank you in advance !
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(“UOM”, total_qty);
});
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.
Hallo guys…this is very interesting! could you make a step-by-step guide for dummies please?
The custom field Total Quantity we are creating know, what data type the custom field Total Quantity should be? Please help me
Generally it should be of type “Float”
Hello @nabinhait,
i need to automaticly copy value from custom field in SI to same custom field in SI Item. Could you help me with this.
Thanks in advance.
frappe.ui.form.on("Sales Invoice", "si_field", function(frm) {
$.each(frm.doc.items || [], function(i, d) {
frappe.model.set_value("Sales Invoice Item", d.name, "si_item_field", frm.doc.si_field);
});
})
The above code will run on change of custom_field in SI and it will assign the same value in all rows in SI Item.
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)
frappe.ui.form.on(“Delivery Note”, “broj_vaucera”, function(frm) {
$.each(frm.doc.items || [], function(i, d) {
frappe.model.set_value(“Delivery note Item”, d.name, “broj_vaucera”, frm.doc.broj_vaucera);
});
})
It should be “Delivery Note Item”, it is case sensitive.
And you should create a new Custom Script record, select doctype as “Delivery Note” and paste the code there in script field.
Its working! Great! Thank you.
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.
Hi.
I wanted a total quantity in stock entry(material receipt). So I added custom field with title Total Qty as float and read only. Then added below script to stock entry but not showing anything.
frappe.ui.form.on(“Stock Entry”, “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);
});
Am I doing any thing wrong?
Also while adding section and column break before Total Qty it is asking me to add label! What to do?
Thanks for a great software.
It should be “Stock Entry Detail”
Enter a label for Section and Column breaks too