Skip to content

Commit

Permalink
fix: Multiple fixes for General Ledger Report
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarvora committed Jul 2, 2024
1 parent 960c85e commit 6c554e1
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License: GNU General Public License v3. See license.txt


import copy
from collections import OrderedDict

import frappe
Expand All @@ -18,9 +19,6 @@
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
from erpnext.accounts.utils import get_account_currency

# to cache translations
TRANSLATIONS = frappe._dict()


def execute(filters=None):
if not filters:
Expand All @@ -45,19 +43,11 @@ def execute(filters=None):

columns = get_columns(filters)

update_translations()

res = get_result(filters, account_details)

return columns, res


def update_translations():
TRANSLATIONS.update(
dict(OPENING=_("Opening"), TOTAL=_("Total"), CLOSING_TOTAL=_("Closing (Opening + Total)"))
)


def validate_filters(filters, account_details):
if not filters.get("company"):
frappe.throw(_("{0} is mandatory").format(_("Company")))
Expand Down Expand Up @@ -324,26 +314,27 @@ def get_accounts_with_children(accounts):
return

doctype = frappe.qb.DocType("Account")
accounts_detail = (
accounts_data = (
frappe.qb.from_(doctype)
.select(doctype.name, doctype.lft, doctype.rgt)
.select(doctype.lft, doctype.rgt)
.where(doctype.name.isin(accounts))
.run(as_dict=True)
)

conditions = []
for account in accounts_detail:
for account in accounts_data:
conditions.append((doctype.lft >= account.lft) & (doctype.rgt <= account.rgt))

return (frappe.qb.from_(doctype).select(doctype.name).where(Criterion.any(conditions))).run(pluck=True)
return frappe.qb.from_(doctype).select(doctype.name).where(Criterion.any(conditions)).run(pluck=True)


def get_data_with_opening_closing(filters, account_details, accounting_dimensions, gl_entries):
data = []
totals_dict = get_totals_dict()

gle_map = initialize_gle_map(gl_entries, filters)
gle_map = initialize_gle_map(gl_entries, filters, totals_dict)

totals, entries = get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map)
totals, entries = get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map, totals_dict)

# Opening for filtered account
data.append(totals.opening)
Expand Down Expand Up @@ -392,9 +383,9 @@ def _get_debit_credit_dict(label):
)

return _dict(
opening=_get_debit_credit_dict(TRANSLATIONS.OPENING),
total=_get_debit_credit_dict(TRANSLATIONS.TOTAL),
closing=_get_debit_credit_dict(TRANSLATIONS.CLOSING_TOTAL),
opening=_get_debit_credit_dict(_("Opening")),
total=_get_debit_credit_dict(_("Total")),
closing=_get_debit_credit_dict(_("Closing (Opening + Total)")),
)


Expand All @@ -407,17 +398,16 @@ def group_by_field(group_by):
return "voucher_no"


def initialize_gle_map(gl_entries, filters):
def initialize_gle_map(gl_entries, filters, totals_dict):
gle_map = OrderedDict()
group_by = group_by_field(filters.get("group_by"))

for gle in gl_entries:
gle_map.setdefault(gle.get(group_by), _dict(totals=get_totals_dict(), entries=[]))
gle_map.setdefault(gle.get(group_by), _dict(totals=copy.deepcopy(totals_dict), entries=[]))
return gle_map


def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
totals = get_totals_dict()
def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map, totals):
entries = []
consolidated_gle = OrderedDict()
group_by = group_by_field(filters.get("group_by"))
Expand Down

0 comments on commit 6c554e1

Please sign in to comment.