Calculate Amount field in “Sales Taxes and Charges” Item Table based on the current total value of TAX

Hi Guys,

I am trying to Calculate Amount field in “Sales Taxes and Charges” Item Table based on the current total value of TAX multiply by 0.02, as you can see from the screenshot below the amount is 0 not calculated. my goal is override the Amount value field.

Here’s my Custom Script:

frappe.ui.form.on(“Sales Order”, {
before_save: function (frm) {
var totalx = 0;
$.each(frm.doc.taxes_and_charges || , function (i, d) {
if (d.type == “Actual”) {
totalx = d.rate * 0.02;
}
totalx = totalx.toFixed(2); // Set recurring decimal limit
d.tax_amount = totalx;
});
cur_frm.refresh_field(“taxes_and_charges”);
}
});

My setup is Tax Inclussive that need to print,
Total without TAX = 8,695.65
TAX @ 15%= 1,304.35
Grand Total = 10,000.00
OTHERTAX= -173.91 Calculate 10000/1.15*0.02
Rounded Total = 9,826.09

My goal is to come-up the negative value of Amount field in “Sales Taxes and Charges”

Thanks

in your script where you calculate this, just do

on child table

frm.set_value("amount", ( 10000/1.15*0.02) * (-1)) //amount is ur fieldname in your child table

this will set negative --173.91304347826087 in that field

Can you please detail the instruction, where can i put this script, is in my current custom script? I am newbie in ERPNEXT.

Thank you so much for the response very appreciate your time

from where do you fetch the “10000” from ?

please provide more details on how the calculation is handled, not the script, but your requirement

mostly, you’ll have to change your line 1 and 2 to

frappe.ui.form.on('Sales Taxes and Charges',{before_save: function(frm, cdt, cdn){

above line will make the script execute on child table

From the total Amount of all items