Calculate Amount field in "Sales Taxes and Charges" based on two custom fields

Hello Guys,

I want to add two custom fields (AAA and BBB) to the table “Sales Taxes and Charges” and I want to make custom script to calculate AAA * BBB and insert the result to the field Amount which is “tax_amount” when type of the taxes is “Actual” only

This is to get taxes calculated based on quantity when inserting value in any of the custom fields in Sales Order instantly.

Could you please help me out to get this done.

Thank you very much.


I’ll give a shot:

frappe.ui.form.on("Sales Order", {
  before_save: function (frm) {
    var total = 0;
    $.each(frm.doc.taxes_and_charges || [], function (i, d) {
      if (d.type == "Actual") {
        total = d.AAA * d.BBB;
      total = total.toFixed(2); // Set recurring decimal limit
      d.tax_amount = total;

The function will run when you save document
Let me know :wink:

Thank you very much,

It worked as follow:

frappe.ui.form.on(“Sales Order”, {
before_save: function (frm) {
var totalx = 0;
$.each(frm.doc.taxes || [], function (i, d) {
if (d.type = “Actual”) {
totalx = d.AAA * d.BBB;
totalx = totalx.toFixed(2);
d.tax_amount = totalx;

However, is it possible to have the calculation instantly while typing the values in AAA or BBB?

I did the same question 1 year ago hahaha, you can create a custom button below of table to run the calculations if you want it