I would like to create named discounts in sales documents like Cash Discount and Turnover Discount. These discounts would be calculated on Net Total. What is the right approach to implement it. Tried to follow the Additional Discount methodology but failed.
If you set the table total to additional discount amount, it will be easy for you. And the additional discount will automatically set to the net total. You can also set this from a client script or a server script.
I updated the net total and values from server script. But the Taxes and Charges table is not getting updated.
All the values are updated except the Sales Taxes and Charges table.
Do you have a sample to share, how this can be achieved from client script?
Please check the syntax and set the dcotype name, child table name and child table field name in the script.
frappe.ui.form.on('Sales Order', {
validate: function(frm) {
var ttl_dicnt = 0;
if (frm.doc.custom_discounts.length) {
frm.set_value('apply_discount_on', "Net Total");
$.each(frm.doc.custom_discounts, function(i, d) {
ttl_dicnt += flt(d.discount_amount);
});
frm.set_value('discount_amount', ttl_dicnt);
}
}
});
Thank You NCP.
This works in case of multiple discounts on same Net Total.
What if the second discount is applied on the discounted net total.
First 5% cash discount is applied on Net Total, then 8% Turnover Discount is applied on the discounted total.
You have to manage everything in your discounts table; it is the final option.
Otherwise, you need to check the additional discount method and override it in your custom app, but this will apply to both the sales and purchase doctypes since it is defined commonly.
Thank You. Sure will make an attempt.