From e72c98dafb3c6825a66434f26cfd4dd4de66d39a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 24 May 2017 09:01:44 +0530 Subject: [PATCH 1/2] On change of item rate, set margin amount on price list rate, instead of margin percentage (#8988) --- erpnext/public/js/controllers/transaction.js | 8 ++++---- erpnext/selling/sales_common.js | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 44bf21da3e..2d0d83b125 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -15,10 +15,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ // if rate is greater than price_list_rate, set margin // or set discount item.discount_percentage = 0; - item.margin_type = 'Percentage'; - item.margin_rate_or_amount = flt(Math.abs(1 - item.rate / item.price_list_rate) * 100.0, - precision("discount_percentage", item)); - item.rate_with_margin = item.rate; + item.margin_type = 'Amount'; + item.margin_rate_or_amount = flt(item.rate - item.price_list_rate, + precision("margin_rate_or_amount", item)); + item.rate_with_margin = item.rate; } else { item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item)); diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 715434384b..1fcf334717 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -348,9 +348,13 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ margin_type: function(doc, cdt, cdn){ // calculate the revised total margin and rate on margin type changes item = locals[cdt][cdn]; - this.apply_pricing_rule_on_item(item, doc,cdt, cdn) - this.calculate_taxes_and_totals(); - cur_frm.refresh_fields(); + if(!item.margin_type) { + frappe.model.set_value(cdt, cdn, "margin_rate_or_amount", 0); + } else { + this.apply_pricing_rule_on_item(item, doc,cdt, cdn) + this.calculate_taxes_and_totals(); + cur_frm.refresh_fields(); + } } }); From 88906cfc63a050639779fd45cdc2141ea44d4592 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 24 May 2017 09:37:26 +0600 Subject: [PATCH 2/2] bumped to version 8.0.37 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index ad827e5b27..076baeaac7 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import frappe -__version__ = '8.0.36' +__version__ = '8.0.37' def get_default_company(user=None):