Merge pull request #55770 from frappe/mergify/bp/version-15-hotfix/pr-55758

fix: update round off account functions to accept document context for regional overrides (backport #55758)
This commit is contained in:
Lakshit Jain
2026-06-22 18:13:50 +05:30
committed by GitHub
3 changed files with 32 additions and 5 deletions

View File

@@ -38,7 +38,9 @@ class calculate_taxes_and_totals:
self._items = self.filter_rows() if self.doc.doctype == "Quotation" else self.doc.get("items")
get_round_off_applicable_accounts(self.doc.company, frappe.flags.round_off_applicable_accounts)
get_round_off_applicable_accounts(
self.doc.company, frappe.flags.round_off_applicable_accounts, self.doc
)
self.calculate()
def filter_rows(self):
@@ -1128,14 +1130,14 @@ def get_itemised_tax_breakup_html(doc):
@frappe.whitelist()
def get_round_off_applicable_accounts(company, account_list):
def get_round_off_applicable_accounts(company, account_list, doc=None):
# required to set correct region
with temporary_flag("company", company):
return get_regional_round_off_accounts(company, account_list)
return get_regional_round_off_accounts(company, account_list, doc)
@erpnext.allow_regional
def get_regional_round_off_accounts(company, account_list):
def get_regional_round_off_accounts(company, account_list, doc=None):
pass

View File

@@ -1,3 +1,5 @@
from unittest.mock import patch
import frappe
from frappe.tests.utils import FrappeTestCase
@@ -6,6 +8,28 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde
class TestTaxesAndTotals(FrappeTestCase):
def test_regional_round_off_accounts(self):
"""
Regional overrides cannot extend the list in-place — the return
value must be assigned back to frappe.flags.round_off_applicable_accounts.
"""
test_account = "_Test Round Off Account"
def mock_regional(company, account_list: list, doc=None) -> list:
# Simulates a regional override
account_list.extend([test_account])
return account_list
so = make_sales_order(do_not_save=True)
with patch(
"erpnext.controllers.taxes_and_totals.get_regional_round_off_accounts",
mock_regional,
):
calculate_taxes_and_totals(so)
self.assertIn(test_account, frappe.flags.round_off_applicable_accounts)
def test_disabling_rounded_total_resets_base_fields(self):
"""Disabling rounded total should also clear base rounded values."""
so = make_sales_order(do_not_save=True)

View File

@@ -207,7 +207,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
"method": "erpnext.controllers.taxes_and_totals.get_round_off_applicable_accounts",
"args": {
"company": me.frm.doc.company,
"account_list": frappe.flags.round_off_applicable_accounts
"account_list": frappe.flags.round_off_applicable_accounts,
"doc": me.frm.doc,
},
callback(r) {
if (r.message) {