Calculate total and outstanding amount trigger function

Hello,

I have an app which sets the item price to zero in the items table when a certain condition is satisfied.
The item prices are set to zero but the total amount and outstanding amount aren’t recalculated.

Is there a trigger function to make the recalculation i can call from my Python script ?

Thanks

I think there’s function in the JS you can execute manually, but I don’t think that will be needed as the system will automatically update the amount field as along as you update the qty and rate which its value depends on.

somehow the scripts not doing so… the item table values become 0 but the outstanding and total does not change when i submit or something…

its only triggered when i add another item or change or manually in UI.

Is it a standard doctype or a custom one?

Standard Sales invoice doctype

You can calculate it yourself using a Custom Script

frappe.ui.form.on("Sales Invoice Item", {
    qty: function(frm, cdt, cdn) {
        var row = frappe.get_doc(cdt, cdn);
        frappe.model.set_value(cdt, cdn, "amount", row.qty * row.rate);
    },
    rate: function(frm, cdt, cdn) {
        var row = frappe.get_doc(cdt, cdn);
        frappe.model.set_value(cdt, cdn, "amount", row.qty * row.rate);
    }
});

This also, should help you a lot: Custom Scripts

I want to be able to call it from the pyhton script…
as i am doing the code and assigning from the pyhton script.

i found i can import and call the function
from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
but not sure the syntax to invoike it

regards,

Hi @Taher_Khalil,

This should do the job. I would prefer to use the validate method instead of calling that one directly.

I could validate that both will do the same thing. The will update the sinv object.

The last sentence is optional, just to check the output in the CMD.