Merge pull request #38218 from rtdany10/account-balance-mismatch
fix: honour currency precision while fetching balance
This commit is contained in:
commit
4f215f1b70
@ -240,7 +240,6 @@ def get_balance_on(
|
|||||||
cond.append("""gle.cost_center = %s """ % (frappe.db.escape(cost_center, percent=False),))
|
cond.append("""gle.cost_center = %s """ % (frappe.db.escape(cost_center, percent=False),))
|
||||||
|
|
||||||
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):
|
||||||
acc.check_permission("read")
|
acc.check_permission("read")
|
||||||
|
|
||||||
@ -286,18 +285,22 @@ def get_balance_on(
|
|||||||
cond.append("""gle.company = %s """ % (frappe.db.escape(company, percent=False)))
|
cond.append("""gle.company = %s """ % (frappe.db.escape(company, percent=False)))
|
||||||
|
|
||||||
if account or (party_type and party) or account_type:
|
if account or (party_type and party) or account_type:
|
||||||
|
precision = get_currency_precision()
|
||||||
if in_account_currency:
|
if in_account_currency:
|
||||||
select_field = "sum(debit_in_account_currency) - sum(credit_in_account_currency)"
|
select_field = (
|
||||||
|
"sum(round(debit_in_account_currency, %s)) - sum(round(credit_in_account_currency, %s))"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
select_field = "sum(debit) - sum(credit)"
|
select_field = "sum(round(debit, %s)) - sum(round(credit, %s))"
|
||||||
|
|
||||||
bal = frappe.db.sql(
|
bal = frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
SELECT {0}
|
SELECT {0}
|
||||||
FROM `tabGL Entry` gle
|
FROM `tabGL Entry` gle
|
||||||
WHERE {1}""".format(
|
WHERE {1}""".format(
|
||||||
select_field, " and ".join(cond)
|
select_field, " and ".join(cond)
|
||||||
)
|
),
|
||||||
|
(precision, precision),
|
||||||
)[0][0]
|
)[0][0]
|
||||||
# if bal is None, return 0
|
# if bal is None, return 0
|
||||||
return flt(bal)
|
return flt(bal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user