From 2e2faa37cd218c3b47a5028ceadad56ffacf40a2 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 2 Feb 2024 18:08:33 +0530 Subject: [PATCH 1/2] fix: Percentage handling in queries (#39692) * fix: Percentage handling in queries * test: Account with percent sign * chore: add test records --- erpnext/accounts/doctype/account/test_account.py | 15 ++++++++++++++- erpnext/accounts/utils.py | 10 +++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index 79b249fd1af..d0ba284f6f8 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -3,7 +3,7 @@ import frappe from frappe.test_runner import make_test_records -from frappe.tests.utils import FrappeTestCase +from frappe.utils import nowdate from erpnext.accounts.doctype.account.account import ( InvalidAccountMergeError, @@ -321,6 +321,19 @@ class TestAccount(FrappeTestCase): acc.account_currency = "USD" self.assertRaises(frappe.ValidationError, acc.save) + def test_account_balance(self): + from erpnext.accounts.utils import get_balance_on + + if not frappe.db.exists("Account", "Test Percent Account %5 - _TC"): + acc = frappe.new_doc("Account") + acc.account_name = "Test Percent Account %5" + acc.parent_account = "Tax Assets - _TC" + acc.company = "_Test Company" + acc.insert() + + balance = get_balance_on(account="Test Percent Account %5 - _TC", date=nowdate()) + self.assertEqual(balance, 0) + def _make_test_records(verbose=None): from frappe.test_runner import make_test_objects diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 5ddeabfa101..dcf2ff4e5b8 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -243,7 +243,7 @@ def get_balance_on( ) else: - cond.append("""gle.cost_center = %s """ % (frappe.db.escape(cost_center, percent=False),)) + cond.append("""gle.cost_center = %s """ % (frappe.db.escape(cost_center),)) if account: if not (frappe.flags.ignore_account_permission or ignore_account_permission): @@ -264,7 +264,7 @@ def get_balance_on( if acc.account_currency == frappe.get_cached_value("Company", acc.company, "default_currency"): in_account_currency = False else: - cond.append("""gle.account = %s """ % (frappe.db.escape(account, percent=False),)) + cond.append("""gle.account = %s """ % (frappe.db.escape(account),)) if account_type: accounts = frappe.db.get_all( @@ -284,11 +284,11 @@ def get_balance_on( if party_type and party: cond.append( """gle.party_type = %s and gle.party = %s """ - % (frappe.db.escape(party_type), frappe.db.escape(party, percent=False)) + % (frappe.db.escape(party_type), frappe.db.escape(party)) ) if company: - cond.append("""gle.company = %s """ % (frappe.db.escape(company, percent=False))) + cond.append("""gle.company = %s """ % (frappe.db.escape(company))) if account or (party_type and party) or account_type: precision = get_currency_precision() @@ -354,7 +354,7 @@ def get_count_on(account, fieldname, date): % (acc.lft, acc.rgt) ) else: - cond.append("""gle.account = %s """ % (frappe.db.escape(account, percent=False),)) + cond.append("""gle.account = %s """ % (frappe.db.escape(account),)) entries = frappe.db.sql( """ -- GitLab From a19cf8fc3ed20164632c453887fd7474bac4e6a8 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Fri, 2 Feb 2024 19:50:17 +0000 Subject: [PATCH 2/2] fix: merge conflict --- erpnext/accounts/doctype/account/test_account.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index d0ba284f6f8..cd10f646d10 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -3,6 +3,7 @@ import frappe from frappe.test_runner import make_test_records +from frappe.tests.utils import FrappeTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.account.account import ( -- GitLab