fix: use account_name only in consolidated report (#24840)
Don't use account_number and only rely on account_name for preparing consolidated financial statement. Related issue: ISS-20-21-10217
This commit is contained in:
parent
0b29f87fa2
commit
2b61491adb
@ -240,8 +240,7 @@ def get_company_currency(filters=None):
|
||||
def calculate_values(accounts_by_name, gl_entries_by_account, companies, start_date, filters):
|
||||
for entries in gl_entries_by_account.values():
|
||||
for entry in entries:
|
||||
key = entry.account_number or entry.account_name
|
||||
d = accounts_by_name.get(key)
|
||||
d = accounts_by_name.get(entry.account_name)
|
||||
if d:
|
||||
for company in companies:
|
||||
# check if posting date is within the period
|
||||
@ -256,7 +255,8 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies):
|
||||
"""accumulate children's values in parent accounts"""
|
||||
for d in reversed(accounts):
|
||||
if d.parent_account:
|
||||
account = d.parent_account.split(' - ')[0].strip()
|
||||
account = d.parent_account_name
|
||||
|
||||
if not accounts_by_name.get(account):
|
||||
continue
|
||||
|
||||
@ -267,16 +267,34 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies):
|
||||
accounts_by_name[account]["opening_balance"] = \
|
||||
accounts_by_name[account].get("opening_balance", 0.0) + d.get("opening_balance", 0.0)
|
||||
|
||||
|
||||
def get_account_heads(root_type, companies, filters):
|
||||
accounts = get_accounts(root_type, filters)
|
||||
|
||||
if not accounts:
|
||||
return None, None
|
||||
|
||||
accounts = update_parent_account_names(accounts)
|
||||
|
||||
accounts, accounts_by_name, parent_children_map = filter_accounts(accounts)
|
||||
|
||||
return accounts, accounts_by_name
|
||||
|
||||
def update_parent_account_names(accounts):
|
||||
"""Update parent_account_name in accounts list.
|
||||
|
||||
parent_name is `name` of parent account which could have other prefix
|
||||
of account_number and suffix of company abbr. This function adds key called
|
||||
`parent_account_name` which does not have such prefix/suffix.
|
||||
"""
|
||||
name_to_account_map = { d.name : d.account_name for d in accounts }
|
||||
|
||||
for account in accounts:
|
||||
if account.parent_account:
|
||||
account["parent_account_name"] = name_to_account_map[account.parent_account]
|
||||
|
||||
return accounts
|
||||
|
||||
def get_companies(filters):
|
||||
companies = {}
|
||||
all_companies = get_subsidiary_companies(filters.get('company'))
|
||||
@ -381,9 +399,9 @@ def set_gl_entries_by_account(from_date, to_date, root_lft, root_rgt, filters, g
|
||||
convert_to_presentation_currency(gl_entries, currency_info, filters.get('company'))
|
||||
|
||||
for entry in gl_entries:
|
||||
key = entry.account_number or entry.account_name
|
||||
validate_entries(key, entry, accounts_by_name, accounts)
|
||||
gl_entries_by_account.setdefault(key, []).append(entry)
|
||||
account_name = entry.account_name
|
||||
validate_entries(account_name, entry, accounts_by_name, accounts)
|
||||
gl_entries_by_account.setdefault(account_name, []).append(entry)
|
||||
|
||||
return gl_entries_by_account
|
||||
|
||||
@ -452,8 +470,7 @@ def filter_accounts(accounts, depth=10):
|
||||
parent_children_map = {}
|
||||
accounts_by_name = {}
|
||||
for d in accounts:
|
||||
key = d.account_number or d.account_name
|
||||
accounts_by_name[key] = d
|
||||
accounts_by_name[d.account_name] = d
|
||||
parent_children_map.setdefault(d.parent_account or None, []).append(d)
|
||||
|
||||
filtered_accounts = []
|
||||
|
Loading…
Reference in New Issue
Block a user