From 367a076fa4c7755406ff81405b196172455cc076 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 13 Nov 2018 18:41:58 +0530 Subject: [PATCH] fix(discount): Fixed item discount amount calculation --- erpnext/controllers/taxes_and_totals.py | 9 +++++---- erpnext/public/js/controllers/taxes_and_totals.js | 2 +- erpnext/public/js/controllers/transaction.js | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 24fe2935792..a4410256f61 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -65,12 +65,13 @@ class calculate_taxes_and_totals(object): if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']: item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) - - item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))\ - if item.rate_with_margin > 0 else item.rate + if flt(item.rate_with_margin) > 0: + item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) + item.discount_amount = item.rate_with_margin - item.rate + elif flt(item.price_list_rate) > 0: + item.discount_amount = item.price_list_rate - item.rate item.net_rate = item.rate - item.discount_amount = item.rate_with_margin - item.rate item.amount = flt(item.rate * item.qty, item.precision("amount")) item.net_amount = item.amount diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 21e02b7c80b..a2d44c3ae24 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -13,8 +13,8 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ + flt(effective_item_rate) * ( flt(item.margin_rate_or_amount) / 100); } else { item.rate_with_margin = flt(effective_item_rate) + flt(item.margin_rate_or_amount); - item.base_rate_with_margin = flt(item.rate_with_margin) * flt(this.frm.doc.conversion_rate); } + item.base_rate_with_margin = flt(item.rate_with_margin) * flt(this.frm.doc.conversion_rate); item.rate = flt(item.rate_with_margin , precision("rate", item)); diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index f3c29fce78e..a33b87f619e 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -33,6 +33,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ item.margin_rate_or_amount = 0; item.rate_with_margin = 0; } + item.base_rate_with_margin = item.rate_with_margin * flt(this.frm.doc.conversion_rate); cur_frm.cscript.set_gross_profit(item); cur_frm.cscript.calculate_taxes_and_totals();