Skip to content

Instantly share code, notes, and snippets.

@nathando
Created November 7, 2014 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathando/004cb8d8e97e426119a1 to your computer and use it in GitHub Desktop.
Save nathando/004cb8d8e97e426119a1 to your computer and use it in GitHub Desktop.
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