Skip to content

Commit

Permalink
Merge pull request #43683 from frappe/mergify/bp/version-14-hotfix/pr…
Browse files Browse the repository at this point in the history
…-43661

fix: missing child company accounts in consolidated balance sheet (backport #43661)
  • Loading branch information
ruthra-kumar authored Oct 15, 2024
2 parents 7005008 + bb774ce commit 2e6ead3
Showing 1 changed file with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,13 @@ def update_parent_account_names(accounts):

for d in accounts:
if d.account_number:
account_name = d.account_number + " - " + d.account_name
account_key = d.account_number + " - " + d.account_name
else:
account_name = d.account_name
name_to_account_map[d.name] = account_name
account_key = d.account_name

d.account_key = account_key

name_to_account_map[d.name] = account_key

for account in accounts:
if account.parent_account:
Expand Down Expand Up @@ -510,33 +513,26 @@ def get_subsidiary_companies(company):

def get_accounts(root_type, companies):
accounts = []
added_accounts = []

for company in companies:
for account in frappe.get_all(
"Account",
fields=[
"name",
"is_group",
"company",
"parent_account",
"lft",
"rgt",
"root_type",
"report_type",
"account_name",
"account_number",
],
filters={"company": company, "root_type": root_type},
):
if account.account_number:
account_key = account.account_number + "-" + account.account_name
else:
account_key = account.account_name

if account_key not in added_accounts:
accounts.append(account)
added_accounts.append(account_key)
accounts.extend(
frappe.get_all(
"Account",
fields=[
"name",
"is_group",
"company",
"parent_account",
"lft",
"rgt",
"root_type",
"report_type",
"account_name",
"account_number",
],
filters={"company": company, "root_type": root_type},
)
)

return accounts

Expand Down Expand Up @@ -775,15 +771,17 @@ def add_total_row(out, root_type, balance_must_be, companies, company_currency):
def filter_accounts(accounts, depth=10):
parent_children_map = {}
accounts_by_name = {}
added_accounts = []

for d in accounts:
if d.account_number:
account_name = d.account_number + " - " + d.account_name
else:
account_name = d.account_name
if d.account_key in added_accounts:
continue

added_accounts.append(d.account_key)
d["company_wise_opening_bal"] = defaultdict(float)
accounts_by_name[account_name] = d
accounts_by_name[d.account_key] = d

parent_children_map.setdefault(d.parent_account or None, []).append(d)
parent_children_map.setdefault(d.parent_account_name or None, []).append(d)

filtered_accounts = []

Expand All @@ -795,7 +793,7 @@ def add_to_list(parent, level):
for child in children:
child.indent = level
filtered_accounts.append(child)
add_to_list(child.name, level + 1)
add_to_list(child.account_key, level + 1)

add_to_list(None, 0)

Expand Down

0 comments on commit 2e6ead3

Please sign in to comment.