diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index eeb90929fc7e4f14a37a1b0c9b67497e8ee20e0e..9cfeefb39b0a2337bdda15335faf0212ffbc745a 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -402,6 +402,9 @@ class calculate_taxes_and_totals: self._calculate() def calculate_taxes(self): + # reset value from earlier calculations + self.grand_total_diff = 0 + doc = self.doc if not doc.get("taxes"): return @@ -689,7 +692,7 @@ class calculate_taxes_and_totals: self.grand_total_diff = 0 def calculate_totals(self): - grand_total_diff = getattr(self, "grand_total_diff", 0) + grand_total_diff = self.grand_total_diff if self.doc.get("taxes"): self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + grand_total_diff diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 4ff6591ace79618aa4612e19dda41eae5f72e13e..8a598c98565b4288d2557ffe4cc8b4babd959028 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -394,6 +394,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } calculate_taxes() { + // reset value from earlier calculations + this.grand_total_diff = 0; + const doc = this.frm.doc; if (!doc.taxes?.length) return; @@ -631,6 +634,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { if (diff && Math.abs(diff) <= 5.0 / Math.pow(10, precision("tax_amount", last_tax))) { me.grand_total_diff = diff; + } else { + me.grand_total_diff = 0; } } } @@ -640,7 +645,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { // Changing sequence can cause rounding_adjustmentng issue and on-screen discrepency const me = this; const tax_count = this.frm.doc.taxes?.length; - const grand_total_diff = this.grand_total_diff || 0; + const grand_total_diff = this.grand_total_diff; this.frm.doc.grand_total = flt( tax_count ? this.frm.doc["taxes"][tax_count - 1].total + grand_total_diff : this.frm.doc.net_total