Changes in Grand Total does not reflact in Purchase Invoice

There is my code

frappe.ui.form.on("Purchase Invoice","refresh", function(frm, doctype, name) {
	cur_frm.doc.grand_total = 10000; // some value based on some calculation

Here I am trying to change ‘grand total’ value based on some calculation in ‘refresh’ but it is not changed. Can anybody explain, why this is happening?

You should do the calculation part when the field which is used to calculate the grand total is changed.

frappe.ui.form.on("Purchase Invoice", "some_fieldname", function(frm, doctype, name) {
    frm.set_value('grand_total', calculated_value);

Thanks… I got your point, but my doubt is that why it is not changed in ‘refresh’ or ‘onload’