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