fix: Percentage handling in queries (#39692)
fix: Percentage handling in queries (#39692) * fix: Percentage handling in queries * test: Account with percent sign * chore: add test records (cherry picked from commit 6d87cfeb8d87b6faed8a7238cd8cf97df2acd99d) Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
parent
41e46326c0
commit
e76f59803c
@ -6,6 +6,7 @@ import unittest
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.test_runner import make_test_records
|
from frappe.test_runner import make_test_records
|
||||||
|
from frappe.utils import nowdate
|
||||||
|
|
||||||
from erpnext.accounts.doctype.account.account import (
|
from erpnext.accounts.doctype.account.account import (
|
||||||
InvalidAccountMergeError,
|
InvalidAccountMergeError,
|
||||||
@ -324,6 +325,19 @@ class TestAccount(unittest.TestCase):
|
|||||||
acc.account_currency = "USD"
|
acc.account_currency = "USD"
|
||||||
self.assertRaises(frappe.ValidationError, acc.save)
|
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):
|
def _make_test_records(verbose=None):
|
||||||
from frappe.test_runner import make_test_objects
|
from frappe.test_runner import make_test_objects
|
||||||
|
@ -237,7 +237,7 @@ def get_balance_on(
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
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 account:
|
||||||
if not (frappe.flags.ignore_account_permission or ignore_account_permission):
|
if not (frappe.flags.ignore_account_permission or ignore_account_permission):
|
||||||
@ -258,7 +258,7 @@ def get_balance_on(
|
|||||||
if acc.account_currency == frappe.get_cached_value("Company", acc.company, "default_currency"):
|
if acc.account_currency == frappe.get_cached_value("Company", acc.company, "default_currency"):
|
||||||
in_account_currency = False
|
in_account_currency = False
|
||||||
else:
|
else:
|
||||||
cond.append("""gle.account = %s """ % (frappe.db.escape(account, percent=False),))
|
cond.append("""gle.account = %s """ % (frappe.db.escape(account),))
|
||||||
|
|
||||||
if account_type:
|
if account_type:
|
||||||
accounts = frappe.db.get_all(
|
accounts = frappe.db.get_all(
|
||||||
@ -278,11 +278,11 @@ def get_balance_on(
|
|||||||
if party_type and party:
|
if party_type and party:
|
||||||
cond.append(
|
cond.append(
|
||||||
"""gle.party_type = %s and gle.party = %s """
|
"""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:
|
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:
|
if account or (party_type and party) or account_type:
|
||||||
precision = get_currency_precision()
|
precision = get_currency_precision()
|
||||||
@ -348,7 +348,7 @@ def get_count_on(account, fieldname, date):
|
|||||||
% (acc.lft, acc.rgt)
|
% (acc.lft, acc.rgt)
|
||||||
)
|
)
|
||||||
else:
|
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(
|
entries = frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user