Purchase Invoice calculation client script not work

Hello ,
I try to edit amount field in purchase invoice to be stock_qty * rate but it not working for me
i tried this script


and this script (this script worked correctly with sales invoice , but for purchase didn’t work

Thanks in advance

Hi,

Try with before_save instead of after_save.

Thanks,

Divyesh Mangroliya

1 Like

Doesn’t work too

hello
is there any solutions ?

Hi @creativeps,

First thing, you can’t override the base amount field calculation because the amount field is connected with lots of methods like total tax calculation, shipping cost, etc.

I think you should create a custom field like custom_amount and then set your scenario according.

Check the below syntax

frappe.ui.form.on('Purchase Invoice Item', {
   stock_qty: function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       update_vals(frm, cdt, cdn);
   },
   rate: function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       update_vals(frm, cdt, cdn);
   }
});

function update_vals(frm, cdt, cdn) {
    frappe.model.set_value(cdt, cdn, 'custom_amount', d.stock_qty * d.rate);
}

Please check your child’s table field name and set it accordingly.

Thank You!

1 Like

Thanks Very Much

I tried this but it’s not worked

71