How to get GrandTotal updated?

Hi,

In our application, we need to change each item price rate when saving a Delivery Note, and then we need to calculate a discount amount from the new grand total. But the problem is, the grand total is not updated yet. How can I make sure that the grand total is updated right after I have changed all the item price rate?

Here’s an example of my custom script.

frappe.ui.form.on(“Delivery Note”, {
validate: function(frm) {
cur_frm.doc.items.forEach(function(item){
item.rate = 0.75*item.price_list_rate;
})
msgprint(frm.doc.grand_total); // Still showing old value of Grand Total here.
}});

Hi,

try refreshing the fields before msgprint use frm.refresh_field('items') or frm.refresh_fields()

Thanks, Makarand

1 Like

Thanx. But didn’t work. I modified the code to be like this:

frappe.ui.form.on("Delivery Note", {
validate: function(frm) {
cur_frm.doc.items.forEach(function(item){
item.rate = 0.75*item.price_list_rate;
})

cur_frm.refresh_field('items');
cur_frm.refresh_fields();
msgprint(frm.doc.grand_total); // Still showing old value of Grand Total here.
}});

Hi,

This code is not working because after changing rate the further calculations may not be triggered you can manually trigger those by adding following line

frm.cscript.recalculate()

But I am not sure if its the right way to do this, Can you please share the use case ?

It seems that you are applying the discount on the Price List Rate. In that case please use the Pricing Rule instade, Please check Pricing Rule

Thanks, Makarand

Thank you very much. That worked.

I have a pricing rule that can’t be easily implemented using the Pricing Rule here.

Please look at my posting with title:
Different Price List for Different Customer Group and Different Product Group?

So I am trying to apply a discount using some custom parameters in Customer Doc.