I am working on ERPNExt V14 and I had t create a duplicate from Quotation Doctype. The rate and amount weren’t working, I had to use client script(Someone here helped me with that) to get the amount to be calculated and also, the total and grand total. I observed Sales Taxes and Charges Template isn’t pulling the pre-saved value and applying it as it does in original Doctypes. How do I get this to work?
Here is the client script in use:
frappe.ui.form.on("Prop Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateTotal(frm);
},
rate: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateTotal(frm);
},
});
function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function (item) {
total += item.amount;
});
frm.set_value("total", total);
}
frappe.ui.form.on("Prop Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateGrandTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateGrandTotal(frm);
},
rate: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateGrandTotal(frm);
},
});
function calculateGrandTotal(frm) {
var grand_total = 0;
frm.doc.items.forEach(function (item) {
grand_total += item.amount;
});
frm.set_value("grand_total", grand_total);
}
Thank you