Get Total Amount?

how to get total amount i create table. see the reference below.

ill try to multiply the QTY * unit price but isnt working.

this is my code!

cur_frm.cscript.custom_pr_amt = function(doc){
	totalamount = doc.pr_qty * doc.pr_unitprice; 
	cur_frm.set_value("pr_amt",totalamount);  
}

Hi @Denmark_Del_Puso,
Do you want to set value for the field in the child table or in doctype? You can write a function which will trigger when the unit price or amount in the child table will change.

Hi! @ManasSolanki thanks for your response.

i want to set value for the field in the child table.

Hi,
You can use following script:

frappe.ui.form.on("name_of_child_doctype", {
        field_name: function(frm) {
            frm.events.function_name();
         }
       function_name: function(frm) {
           // code for total here
       }
})

Hello @Denmark_Del_Puso

Please try following code.

frappe.ui.form.on("Child Tabel Name", "unit_price", function(frm, cdt, cdn){
    
    cur_frm.refresh();
    cur_frm.refresh_fields();
    var d = locals[cdt][cdn];
    frappe.model.set_value(d.doctype, d.name, "amount", d.qty * d.unit_price);
   
    }                
}); 

Thanks,
Hardik Gadesha
Software Engineer : AIMDek Technologies PVT. LTD

hi! @Hardik_Gadesha and @ManasSolanki your code isnt working. stil the same. didnt compute

this is my doctype

and this is my child table

@Denmark_Del_Puso then you have to change field name according to your doctype.

For above given code : replace following

  1. amount ==> pr_amt
  2. unit_price ==> pr_unitprice
  3. d.qty ==> d.pr_qty
  4. d.unit_price ==> d.pr_unitprice
  5. child Table name ==> PR Item Details

Thanks,
Hardik Gadesha

Hi! @Hardik_Gadesha thankyou for your response again, ill try to change but the problem still the same. the value of amount is “0” didnot compute.

@Denmark_Del_Puso

Please Share your code here.

frappe.ui.form.on(“PR Item Details”, “pr_unitprice”, function(frm, cdt, cdn){
cur_frm.refresh();
cur_frm.refresh_fields();
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “pr_amt”, d.pr_qty * d.pr_unitprice);
});

Try this @Denmark_Del_Puso

frappe.ui.form.on("PR Item Details", "pr_unitprice", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frappe.model.set_value(cdt, cdn, "pr_amt", d.pr_qty  * d.pr_unitprice);
refresh_field("pr_amt");
});
1 Like

Hi! @Muthu thankyou so much it works.

1 Like

@Denmark_Del_Puso . Glad to help

1 Like