From 2d198e698abeaf79352c106f62c6b53d4bdc02c4 Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Thu, 11 Dec 2025 17:48:37 +0530 Subject: [PATCH] fix: ensure fresh `grand_total_diff` is used for each calculation (cherry picked from commit b3fdef8d19ebb919d496b2f1e6a55706bad34f74) --- erpnext/controllers/taxes_and_totals.py | 5 ++++- erpnext/public/js/controllers/taxes_and_totals.js | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index d6c4b99588c..f059f2908bd 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -378,6 +378,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 @@ -587,7 +590,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 d8c81b726ee..de0a7ab51bc 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -343,6 +343,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; @@ -578,6 +581,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; } } } @@ -587,7 +592,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