From f32fc230f70f7d7bdbdb5a94cbe0c8bace1e16b6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 25 Dec 2019 13:59:24 +0530 Subject: [PATCH] fix: rounding adjustment while both inclusive tax and discount amount present --- erpnext/controllers/taxes_and_totals.py | 12 ++++++++++-- erpnext/public/js/controllers/taxes_and_totals.js | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 66232d7ff1..049a837eaf 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -312,11 +312,19 @@ class calculate_taxes_and_totals(object): last_tax = self.doc.get("taxes")[-1] non_inclusive_tax_amount = sum([flt(d.tax_amount_after_discount_amount) for d in self.doc.get("taxes") if not d.included_in_print_rate]) + diff = self.doc.total + non_inclusive_tax_amount \ - flt(last_tax.total, last_tax.precision("total")) + + # If discount amount applied, deduct the discount amount + # because self.doc.total is always without discount, but last_tax.total is after discount + if self.discount_amount_applied and self.doc.discount_amount: + diff -= flt(self.doc.discount_amount) + + diff = flt(diff, self.doc.precision("rounding_adjustment")) + if diff and abs(diff) <= (5.0 / 10**last_tax.precision("tax_amount")): - self.doc.rounding_adjustment = flt(flt(self.doc.rounding_adjustment) + - flt(diff), self.doc.precision("rounding_adjustment")) + self.doc.rounding_adjustment = diff def calculate_totals(self): self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + flt(self.doc.rounding_adjustment) \ diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 2ece711040..28fb649025 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -388,9 +388,14 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ var diff = me.frm.doc.total + non_inclusive_tax_amount - flt(last_tax.total, precision("grand_total")); + if(me.discount_amount_applied && me.frm.doc.discount_amount) { + diff -= flt(me.frm.doc.discount_amount); + } + + diff = flt(diff, precision("rounding_adjustment")); + if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) { - this.frm.doc.rounding_adjustment = flt(flt(this.frm.doc.rounding_adjustment) + diff, - precision("rounding_adjustment")); + me.frm.doc.rounding_adjustment = diff; } } }