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?
Computer doesnt make mistake, but I am getting an issue in total qty! Total qty should be 263043 but showing 518598?
Below is script I used as you instruct me. Custom field name is Total Qty(total_qty)
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(“YOUR_CHILD_TABLE_FIELD”).grid.grid_rows.length; i++) {
total_qty += cur_frm.get_field(“YOUR_CHILD_TABLE_FIELD”).grid.grid_rows[i].doc.field_under_child_table;
}
hi
Iam facing a similar situation
need to create a total qty in stock entry
did the following
created a field “Total Qty” (total_qty) in “STOCK ENTRY”
created a custom script for STOCK ENTRY and entered 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);
});
but the results are not being displayed
if you have solved it, could you please help me with a step by step procedure
Regards
Hemanth
Hi jof2jc
thanks a lot
that code worked like charm
it works only with new stock entries
older stock entries are throwing up error
what language is used here
can you guide me to some learning material
thanks a lot again
Hemanth