Calculate total qty in print

Hi
I am trying get the total item qty of stock entry in print
I added a row in the form “stock entry detail” — total_qty ( through customize form ) ( checked “list view” )
I added the following custom script to the form “stock entry detail”

frappe.ui.form.on(“Stock Entry Detail”, “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);
});
iam not able to see any result
please help
hemanth

Please refer to:

Thanks Umair

ok
I create a custom script for the doc “stock entry”
and add this

for (var i = 0; i < cur_frm.get_field(“total_qty”).grid.grid_rows.length; i++) {
total_qty += cur_frm.get_field(“total_qty”).grid.grid_rows[i].doc.field_under_child_table;
}
the stock entry form dosent open any more
hemanth

The code looks ok. But you should put the code in the custom script for “Stock Entry”, not “Stock Entry Detail”.

Hi nabinhait
where should I create the custom field “total_qty”
in stock entry or in stock entry details

the below code should go to “stock entry” or “stock entry details” ?

frappe.ui.form.on(“Stock Entry Detail”, “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);
});
hemanth

hi
I created the custom field “total qty”(total_qty) in “stock entry”

I created a custom script for “stock entry” with the following code

frappe.ui.form.on(“Stock Entry Detail”, “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);
});

for (var i = 0; i < cur_frm.get_field(“total_qty”).grid.grid_rows.length; i++) {
total_qty += cur_frm.get_field(“total_qty”).grid.grid_rows[i].doc.field_under_child_table;
}

now the stock entry that have already been created dosent open
Hemanth