Calculated values cannot be set in the doctype when it is saved

frappe.ui.form.on("Sales Order Item", {
	item_code: function (frm, cdt, cdn) {
		var row = locals[cdt][cdn];
		if (frm.doc.delivery_date) {
			row.delivery_date = frm.doc.delivery_date;
			refresh_field("delivery_date", cdn, "items");
		} else {
			frm.script_manager.copy_from_first_row("items", row, ["delivery_date"]);
		}
	},
	delivery_date: function (frm, cdt, cdn) {
		if (!frm.doc.delivery_date) {
			erpnext.utils.copy_value_in_all_rows(frm.doc, cdt, cdn, "items", "delivery_date");
		}
	},
	rate_per_liter: function (frm, cdt, cdn) {
		calculate_subtotal(frm, cdt, cdn);
	},
	qty: function (frm, cdt, cdn) {
		calculate_subtotal(frm, cdt, cdn);
	},
	amount_excluding_gst: function (frm, cdt, cdn) {
		calculate_subtotal(frm, cdt, cdn);
	},
	quantity__litters: function (frm, cdt, cdn) {
		calculate_subtotal(frm, cdt, cdn);
	},
	rate_of_gst: function (frm, cdt, cdn) {
		calculate_subtotal(frm, cdt, cdn);
	},

	amount_of_gst: function (frm, cdt, cdn) {
		calculate_subtotal(frm, cdt, cdn);
	},

});
function calculate_subtotal(frm, cdt, cdn) {
	var row = locals[cdt][cdn];
	if (row.rate_per_liter && row.qty) {
		row.sub_total = row.rate_per_liter * row.qty;
		row.amount_excluding_gst = row.sub_total;

		if (row.rate_of_gst) {
			const gstPercentage = parseFloat(row.rate_of_gst.replace("%", ""));
			row.amount_of_gst = row.sub_total * gstPercentage / 100;
		}

		if (row.amount_of_gst && row.sub_total) {

			row.amount = row.amount_of_gst + row.sub_total;
			// its log the calculated values 
			console.log("row.amount", row.amount);
		}

		refresh_field('sub_total', row.name, row.parentfield);
		refresh_field('amount_of_gst', row.name, row.parentfield);
		refresh_field('amount_excluding_gst', row.name, row.parentfield);
		// refresh the fields 'amount' present in parent doctype of Sales Order Item
		refresh_field('amount', row.name, row.parentfield);

	}
}

‘Amount’ is the highlighted marked column here, and the code I provided above calculates

@Muhammad_Junaid what is the problem exactly ?

row.amount = row.amount_of_gst + row.sub_total
problem is expected output is ( amount_of_gst + sub_total ) but row.amount show a sub_total value after i save doc.
And the row.amount is ('Total Invoice Amount ') table column name in the ui.

'Total Invoice Amount ’ should be display amount_of_gst(75861.32400000001) + sub_total(421451.80000000005) = 497,313.12

@Muhammad_Junaid before you save the doc and following the your js code does the value change ?

no, its not change the value expected.

@Muhammad_Junaid do you see the console.log ?

yes, just tell me where calculate the grandtotal

@Muhammad_Junaid try refreshing the entire table with refresh_field(“items”) instead all the refreshing you doing .

and try to change the value directly in locals[cdt][cdn].