How to do calculation in child table rows

I want to multiply qty and weight and set result is total weight,
Screenshot 2024-04-13 at 9.09.09 PM
to achieve this I am using following script but it does not work.
is it correct script?

frappe.ui.form.on("Gatepass Detail", {
	qty: function(frm,cdt, cdn){
		calculate_total(frm, cdt, cdn);
	}
});
var calculate_total = function(frm, cdt, cdn) {
	var child = locals[cdt][cdn];
	frappe.model.set_value(cdt, cdn, "total-weight", child.qty * child.weight);
}

Hi @Max_Fun,

Please check the fieldname because if there is no (-), only underscore (_) appears when creating the field. Go to the customize form and check the field name.

Reference:

1 Like
frappe.ui.form.on("Gatepass Detail", {
    quantity: function(frm, cdt, cdn) {
        calculateTotalWeight(frm, cdt, cdn);
    },
    weight: function(frm, cdt, cdn) {
        calculateTotalWeight(frm, cdt, cdn);
    }
});

function calculateTotalWeight(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
    var totalValue = d.quantity * d.weight;
    frappe.model.set_value(cdt, cdn, 'total_weight', totalValue);
    // Optionally refresh the field if necessary
    // frm.refresh_field('total_weight');
}