Custom Fields Calculation on child table

Hello,
on my quotation item i created three custom fields GST, GST Amount, Total Amount. can be seen in below pic


i calculated the gst amount with help the following script

frappe.ui.form.on('Quotation Item', {
	gst:function(frm,cdt,cdn){
		var d = locals[cdt][cdn];
		var gst_amount = flt(d.amount) * flt(d.gst) / 100 ;
		frappe.model.set_value(cdt, cdn, "gst_amount", gst_amount);
	}
})

now i want to modify this script to calculate the total amount field.
total_amount = amount + gst_amount

Hi,
use loop for gst_amount calculation and then set total_amount value.

Actually i m not good at scripting thats why i asked

any one …

Hi,
use it, it worked.

3 Likes

Works like a charm. thanks

@Jitendra_Rathod I need one last modification to this script …
the script calculation trigger whenever i update gst field which is the way i wanted. but i need the scrip to recalculate the values when the amount field updated.

Hi,
use it.
amount:function(frm,cdt,cdn){
“====your script====”
}

1 Like

there was issues to set script for the amount field as it is read only field and not input field. anyway i modify the script a bit and its working for my current situation sharing the script as it might helpful for the community.

frappe.ui.form.on('Quotation Item', {
	gst:function(frm,cdt,cdn){
		var d = locals[cdt][cdn];
		var gst_amount = (flt(d.qty) * flt(d.rate)) * flt(d.gst) / 100 ;
		frappe.model.set_value(cdt, cdn, "gst_amount", gst_amount);
		var total = (flt(d.qty) * flt(d.rate)) + flt (d.gst_amount);
		frappe.model.set_value(cdt, cdn, 'total_amount', total);
	},
	qty:function(frm,cdt,cdn){
		var d = locals[cdt][cdn];
		var gst_amount = (flt(d.qty) * flt(d.rate)) * flt(d.gst) / 100 ;
		frappe.model.set_value(cdt, cdn, "gst_amount", gst_amount);
		var total = (flt(d.qty) * flt(d.rate)) + flt (d.gst_amount);
		frappe.model.set_value(cdt, cdn, 'total_amount', total);
	},
	rate:function(frm,cdt,cdn){
		var d = locals[cdt][cdn];
		var gst_amount = (flt(d.qty) * flt(d.rate)) * flt(d.gst) / 100 ;
		frappe.model.set_value(cdt, cdn, "gst_amount", gst_amount);
		var total = (flt(d.qty) * flt(d.rate)) + flt (d.gst_amount);
		frappe.model.set_value(cdt, cdn, 'total_amount', total);
	}
})
1 Like