Onchange of Sales Invoice Item Qty it should display on Sales Invoice

Onchange of Sales Invoice Item Qty I want to display sum of qty of Sales Invoice Item should display on Sales Invoice

Have you tried anything?

No I could not because I don’t know that how I will it be written.

frappe.ui.form.on("Sales Invoice Item", "qty", function(frm, cdt, cdn) {
	var row = locals[cdt][cdn];
	// code for calculate total and set on parent field.
});

Also check existing similar functionality.

2 Likes

Would you please write syntax to update Parent form field? Can I use for loop to sum all rows QTY?

I have already written that in your other thread:

1 Like
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);
});
1 Like

Mr Nabin, if I copy this code in the invoice. Will it calculate the SUM.

@loliflimited It will almost work. Only thing you need to change is fieldname of custo field “total qty”, in this case it is “net_weight”.

@nabinhait what should be the date type of custom field “total qty” ?

We generally use “Float” fieldtype for qty field.

dear
thanks a lot

i try your code and really it works well for qty

But when i attempt to make it works against another Tables Column it fails

This is my script

i am trying to sum the gm column and put it in the custom filed Total Gm

so it suppose Total GM = 60+30=90
But actually it didnt works !

please advice me.
thanks a lot

hello

I have same sort of problem where i want to calculate the total items in one sales invoice.as per previous guidelines I have created custom field “total_qty” of float type to store total items involved. and added following script on sales invoice custom script section but it’s not working.
please have a look on it.

frappe.ui.form.on(“Sales Invoice”, {
validate: function(frm) {
total_qty = 0;
$.each(frm.doc.items || [], function(i, d) {
total_qty += flt(d.qty);
});
frm.set_value(“net_weight”, total_qty);
}
});

frappe.ui.form.on(“Sales Invoice”, “refresh”, function(frm, cdt, cdn) {
total_qty = 0;
$.each(frm.doc.items || [], function(i, d) {
total_qty += flt(d.qty);
});
frm.set_value(“total_qty”, total_qty);
});

This worked for me…!

Thanks for the update - you fixed your problem!

Please don’t direct requests to individuals to seek their help, unless you have that understanding with them.

cheers

1 Like