Try ERPNext Buy Support Partners Foundation Foundation Members

Child Table Calculation

Hello @Hafees_Kazhunkil @cpurbaugh

Is there any possibilities for above scenario ?

many thanks brother

@Hardik_Gadesha, @Hafees_Kazhunkil, @cpurbaugh
please give me your assist on this issue
if i want to add a 5th column on the table and make the field to be calculated by column1 * column2 what should i do?
thanks in advance for your support

This may help:

//The following three scripts calculates the rate/amount based on quantity.
frappe.ui.form.on("Material Request Item", {
      rate: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(d.doctype, d.name, 'amount', (d.qty * d.rate));
        var total = 0;
        frm.doc.items.forEach(function(d) {
            total += d.amount;
        });
        frm.set_value('total_amount', total);
    },
      qty: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(d.doctype, d.name, 'amount', (d.qty * d.rate));
        var total = 0;
        frm.doc.items.forEach(function(d) {
            total += d.amount;
        });
        frm.set_value('total_amount', total);
    },
      amount: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
        frappe.model.set_value(d.doctype, d.name, 'rate', (d.amount / d.qty));
        var total = 0;
        frm.doc.items.forEach(function(d) {
            total += d.amount;
        });
        frm.set_value('total_amount', total);
    }
});

@cpurbaugh
thanks for your replay
here is my case my child table name is Activityitem and parent doc type is Activity Type
my 3 columns are itemquantity,itemcost and itemtotalost
and what i need is itemquantity * itemcost =itemtotalcost
and here is my code
frappe.ui.form.on(“Activityitem”, {
itemcost: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.Activityitem, ‘itemtotalcost’, (d.itemquantity * d.itemcost));
var total = 0;
frm.doc.items.forEach(function(d) {
total += d.itemtotalcost;
});
frm.set_value(‘total_amount’, total);
},
itemquantity : function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.Activityitem, ‘itemtotalcost’, (d.itemquantity * d.itemcost));
var total = 0;
frm.doc.items.forEach(function(d) {
total += d.itemtotalcost;
});
frm.set_value(‘total_amount’, total);
},
itemtotalcost: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.Activityitem, ‘itemcost’, (d.amount / d.itemquantity));
var total = 0;
frm.doc.items.forEach(function(d) {
total += d.itemtotalcost;
});
frm.set_value(‘total_amount’, total);
}
});
but not working.
please give me your advice.
thanks in advance

@fikerjayz

  frappe.ui.form.on("Activityitem", {
          itemquantity: function(frm, cdt, cdn) {
            var d = locals[cdt][cdn];
                    frappe.model.set_value(d.doctype, d.name, 'itemtotalcost', (d.itemquantity * d.itemcost));   
         },
          itemcost: function(frm, cdt, cdn) {
            var d = locals[cdt][cdn];
                    frappe.model.set_value(d.doctype, d.name, 'itemtotalcost', (d.itemquantity * d.itemcost));   
        }
    }); 

Please Check Child Doctype Name, Field Name twice and confirm

@Hardik_Gadesha, @cpurbaugh
thanks for your support
but its not making the calculation, what shall i amend
frappe.ui.form.on(“Activityitem”, {
itemquantity: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, ‘itemtotalcost’, (d.itemquantity * d.itemcost));
},
itemcost: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, ‘itemtotalcost’, (d.itemquantity * d.itemcost));
}
});

Post Screen shot of your doctype schema

@Hardik_Gadesha


here is the doctype

@fikerjayz

frappe.ui.form.on("Activityitem", {
      itemquantity: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
                frappe.model.set_value(d.doctype, d.name, 'itemtotalcost', (d.itemquantity * d.itemcost));   
     }
 });  

frappe.ui.form.on("Activityitem", {
      itemcost: function(frm, cdt, cdn) {
        var d = locals[cdt][cdn];
                frappe.model.set_value(d.doctype, d.name, 'itemtotalcost', (d.itemquantity * d.itemcost));   
    }
});

can you share me your code? I have an identical case which requires custom script like yours
 Thanks before