Skip to content

Instantly share code, notes, and snippets.

@nathando
Created November 5, 2014 10:18
Show Gist options
  • Select an option

  • Save nathando/efc9ef532e2142b57485 to your computer and use it in GitHub Desktop.

Select an option

Save nathando/efc9ef532e2142b57485 to your computer and use it in GitHub Desktop.
Sales Order - Amount Fixed
// 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);
if (!cur_frm.fixed_amt) {
item.amount = flt(item.rate * item.qty, precision("amount", 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");
});
}
cur_frm.fixed_amt = false;
},
// 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