Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: honour currency precision while fetching balance #38218

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def get_balance_on(
cond.append("""gle.cost_center = %s """ % (frappe.db.escape(cost_center, percent=False),))

if account:

if not (frappe.flags.ignore_account_permission or ignore_account_permission):
acc.check_permission("read")

Expand Down Expand Up @@ -283,18 +282,22 @@ def get_balance_on(
cond.append("""gle.company = %s """ % (frappe.db.escape(company, percent=False)))

if account or (party_type and party) or account_type:

precision = frappe.db.escape(get_currency_precision())
rtdany10 marked this conversation as resolved.
Show resolved Hide resolved
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:
select_field = "sum(debit) - sum(credit)"
select_field = "sum(round(debit, %s)) - sum(round(credit, %s))"

bal = frappe.db.sql(
"""
SELECT {0}
FROM `tabGL Entry` gle
WHERE {1}""".format(
select_field, " and ".join(cond)
)
),
(precision, precision),
)[0][0]
# if bal is None, return 0
return flt(bal)
Expand Down
Loading