Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change the way Amount is calculated in ERPNext Selling
// Replace with new calculation of item value
cur_frm.cscript.calculate_item_values = function() {
var me = this;
if (!this.discount_amount_applied) {
$.each(this.frm.item_doclist, function(i, item) {
frappe.model.round_floats_in(item);
item.rate = flt(item.amount / item.qty, precision("rate", item));
me._set_in_company_currency(item, "price_list_rate", "base_price_list_rate");
me._set_in_company_currency(item, "rate", "base_rate");
me._set_in_company_currency(item, "amount", "base_amount");
});
}
}
// Calculate back the price then update
cur_frm.cscript.custom_amount = function(doc, dt, dn) {
var sales_order_item = locals[dt][dn];
sales_order_item.rate = sales_order_item.amount/sales_order_item.qty;
cur_frm.fixed_amt = true;
cur_frm.cscript.calculate_taxes_and_totals();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment