Skip to content

Commit

Permalink
fix: Opening balance in presentation currency in Trial Balance report (
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored Jul 9, 2023
1 parent 353d765 commit 4d07e20
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def set_gl_entries_by_account(
if filters and filters.get("presentation_currency") != d.default_currency:
currency_info["company"] = d.name
currency_info["company_currency"] = d.default_currency
convert_to_presentation_currency(gl_entries, currency_info, filters.get("company"))
convert_to_presentation_currency(gl_entries, currency_info)

for entry in gl_entries:
if entry.account_number:
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/financial_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def set_gl_entries_by_account(
)

if filters and filters.get("presentation_currency"):
convert_to_presentation_currency(gl_entries, get_currency(filters), filters.get("company"))
convert_to_presentation_currency(gl_entries, get_currency(filters))

for entry in gl_entries:
gl_entries_by_account.setdefault(entry.account, []).append(entry)
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def get_gl_entries(filters, accounting_dimensions):
)

if filters.get("presentation_currency"):
return convert_to_presentation_currency(gl_entries, currency_map, filters.get("company"))
return convert_to_presentation_currency(gl_entries, currency_map)
else:
return gl_entries

Expand Down
15 changes: 11 additions & 4 deletions erpnext/accounts/report/trial_balance/trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
filter_out_zero_value_rows,
set_gl_entries_by_account,
)
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency

value_fields = (
"opening_debit",
Expand Down Expand Up @@ -178,8 +179,8 @@ def get_rootwise_opening_balances(filters, report_type):
"opening_credit": 0.0,
},
)
opening[d.account]["opening_debit"] += flt(d.opening_debit)
opening[d.account]["opening_credit"] += flt(d.opening_credit)
opening[d.account]["opening_debit"] += flt(d.debit)
opening[d.account]["opening_credit"] += flt(d.credit)

return opening

Expand All @@ -194,8 +195,11 @@ def get_opening_balance(
frappe.qb.from_(closing_balance)
.select(
closing_balance.account,
Sum(closing_balance.debit).as_("opening_debit"),
Sum(closing_balance.credit).as_("opening_credit"),
closing_balance.account_currency,
Sum(closing_balance.debit).as_("debit"),
Sum(closing_balance.credit).as_("credit"),
Sum(closing_balance.debit_in_account_currency).as_("debit_in_account_currency"),
Sum(closing_balance.credit_in_account_currency).as_("credit_in_account_currency"),
)
.where(
(closing_balance.company == filters.company)
Expand Down Expand Up @@ -282,6 +286,9 @@ def get_opening_balance(

gle = opening_balance.run(as_dict=1)

if filters and filters.get("presentation_currency"):
convert_to_presentation_currency(gle, get_currency(filters))

return gle


Expand Down
3 changes: 1 addition & 2 deletions erpnext/accounts/report/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_rate_as_at(date, from_currency, to_currency):
return rate


def convert_to_presentation_currency(gl_entries, currency_info, company):
def convert_to_presentation_currency(gl_entries, currency_info):
"""
Take a list of GL Entries and change the 'debit' and 'credit' values to currencies
in `currency_info`.
Expand All @@ -93,7 +93,6 @@ def convert_to_presentation_currency(gl_entries, currency_info, company):
account_currencies = list(set(entry["account_currency"] for entry in gl_entries))

for entry in gl_entries:
account = entry["account"]
debit = flt(entry["debit"])
credit = flt(entry["credit"])
debit_in_account_currency = flt(entry["debit_in_account_currency"])
Expand Down

0 comments on commit 4d07e20

Please sign in to comment.