fix: missing child company accounts in consolidated balance sheet

(cherry picked from commit 7fae9d57d2)
This commit is contained in:
ljain112
2024-10-15 11:41:00 +05:30
committed by Mergify
parent 802d9b2d4a
commit 4db12fe2da

View File

@@ -469,10 +469,13 @@ def update_parent_account_names(accounts):
for d in accounts: for d in accounts:
if d.account_number: if d.account_number:
account_name = d.account_number + " - " + d.account_name account_key = d.account_number + " - " + d.account_name
else: else:
account_name = d.account_name account_key = d.account_name
name_to_account_map[d.name] = account_name
d.account_key = account_key
name_to_account_map[d.name] = account_key
for account in accounts: for account in accounts:
if account.parent_account: if account.parent_account:
@@ -505,33 +508,26 @@ def get_subsidiary_companies(company):
def get_accounts(root_type, companies): def get_accounts(root_type, companies):
accounts = [] accounts = []
added_accounts = []
for company in companies: for company in companies:
for account in frappe.get_all( accounts.extend(
"Account", frappe.get_all(
fields=[ "Account",
"name", fields=[
"is_group", "name",
"company", "is_group",
"parent_account", "company",
"lft", "parent_account",
"rgt", "lft",
"root_type", "rgt",
"report_type", "root_type",
"account_name", "report_type",
"account_number", "account_name",
], "account_number",
filters={"company": company, "root_type": root_type}, ],
): 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)
return accounts return accounts
@@ -770,15 +766,17 @@ def add_total_row(out, root_type, balance_must_be, companies, company_currency):
def filter_accounts(accounts, depth=10): def filter_accounts(accounts, depth=10):
parent_children_map = {} parent_children_map = {}
accounts_by_name = {} accounts_by_name = {}
for d in accounts: added_accounts = []
if d.account_number:
account_name = d.account_number + " - " + d.account_name
else:
account_name = d.account_name
d["company_wise_opening_bal"] = defaultdict(float)
accounts_by_name[account_name] = d
parent_children_map.setdefault(d.parent_account or None, []).append(d) for d in accounts:
if d.account_key in added_accounts:
continue
added_accounts.append(d.account_key)
d["company_wise_opening_bal"] = defaultdict(float)
accounts_by_name[d.account_key] = d
parent_children_map.setdefault(d.parent_account_name or None, []).append(d)
filtered_accounts = [] filtered_accounts = []
@@ -790,7 +788,7 @@ def filter_accounts(accounts, depth=10):
for child in children: for child in children:
child.indent = level child.indent = level
filtered_accounts.append(child) filtered_accounts.append(child)
add_to_list(child.name, level + 1) add_to_list(child.account_key, level + 1)
add_to_list(None, 0) add_to_list(None, 0)