Child Table Calculations

Hi all…i want to calculate child table(stock entry detail) quantity sum into parent doctype (stock entry)field depends on item group condition.

For example, if my item group is unprocessed seed i want all those items quantity whose item group is unprocessed seed to be calculated in parent field name total unprocessed seed qty.
please help.


Hi @SonalD,

Please apply/try it.

frappe.ui.form.on('Stock Entry',  {
    validate: function(frm) {
        var ttl_qty1 = 0;
        var ttl_qty2 = 0;
        var ttl_qty3 = 0;
        var ttl_qty4 = 0;
        var ttl_qty5 = 0;
        $.each(frm.doc.items,  function(i,  d) {
            if (d.item_group == "Unprocessed Seed") {
                ttl_qty1 += flt(d.qty);
            } else if (d.item_group == "Processed Seed") {
                ttl_qty2 += flt(d.qty);
            } else if (d.item_group == "Remnant Seed") {
                ttl_qty3 += flt(d.qty);
            } else if (d.item_group == "Treated Seed") {
                ttl_qty4 += flt(d.qty);
            } else {
                ttl_qty5 += flt(d.qty);
            }
        });
        frm.doc.total_unprocessed_seed = ttl_qty1;
        frm.doc.total_processed_seed = ttl_qty2;
        frm.doc.total_reminant_seed = ttl_qty3;
        frm.doc.total_treated_seed = ttl_qty4;
        frm.doc.total_untreated_seed = ttl_qty5;
    } 
});

Thank You!

Thank you so much.