Amount calculation

hi all
i create custom script in sales order item for override amount calculation by fowllowing script

frappe.ui.form.on(“Sales Order Item”, “qty2”, function(frm, doctype, name) {
var row = locals[doctype][name];
var calc_qty
calc_qty = row.qty2 * row.sub_unit;
calc_qty += row.xqty;
row.amount = calc_qty * row.sub_rate;

var total_new = 0;
$.each(frm.doc.items || [], function(i, d) {
total_new += flt(d.amount);
frm.set_value(“total”, total_new);

and i edit file taxes_and_totals.js and in line 94 from

item.amount = flt(item.qty * item.rate)


item.amount = flt(((item.qty2 * item.sub_unit)+item.xqty) * item.sub_rate;

item row amount and sales order total is correct it’s work.

but when add new row and seleted new item amount in all row and form total is recalculate back to
item.qty * item.rate

can you advice please.