Sort accounts by account number in financial statements (#13423)
This commit is contained in:
parent
456fdf09cb
commit
af98f5d14d
@ -297,8 +297,7 @@ def filter_accounts(accounts, depth=10):
|
||||
def add_to_list(parent, level):
|
||||
if level < depth:
|
||||
children = parent_children_map.get(parent) or []
|
||||
if parent == None:
|
||||
sort_root_accounts(children)
|
||||
sort_accounts(children, is_root=True if parent==None else False)
|
||||
|
||||
for child in children:
|
||||
child.indent = level
|
||||
@ -310,13 +309,11 @@ def filter_accounts(accounts, depth=10):
|
||||
return filtered_accounts, accounts_by_name, parent_children_map
|
||||
|
||||
|
||||
def sort_root_accounts(roots):
|
||||
def sort_accounts(accounts, is_root=False, key="name"):
|
||||
"""Sort root types as Asset, Liability, Equity, Income, Expense"""
|
||||
|
||||
def compare_roots(a, b):
|
||||
if a.value and re.split('\W+', a.value)[0].isdigit():
|
||||
# if chart of accounts is numbered, then sort by number
|
||||
return cmp(a.value, b.value)
|
||||
def compare_accounts(a, b):
|
||||
if is_root:
|
||||
if a.report_type != b.report_type and a.report_type == "Balance Sheet":
|
||||
return -1
|
||||
if a.root_type != b.root_type and a.root_type == "Asset":
|
||||
@ -325,10 +322,13 @@ def sort_root_accounts(roots):
|
||||
return -1
|
||||
if a.root_type == "Income" and b.root_type == "Expense":
|
||||
return -1
|
||||
else:
|
||||
if re.split('\W+', a[key])[0].isdigit():
|
||||
# if chart of accounts is numbered, then sort by number
|
||||
return cmp(a[key], b[key])
|
||||
return 1
|
||||
|
||||
roots.sort(key = functools.cmp_to_key(compare_roots))
|
||||
|
||||
accounts.sort(key = functools.cmp_to_key(compare_accounts))
|
||||
|
||||
def set_gl_entries_by_account(
|
||||
company, from_date, to_date, root_lft, root_rgt, filters, gl_entries_by_account, ignore_closing_entries=False):
|
||||
|
@ -663,7 +663,7 @@ def get_companies():
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(doctype, parent, company, is_root=False):
|
||||
from erpnext.accounts.report.financial_statements import sort_root_accounts
|
||||
from erpnext.accounts.report.financial_statements import sort_accounts
|
||||
|
||||
fieldname = frappe.db.escape(doctype.lower().replace(' ','_'))
|
||||
doctype = frappe.db.escape(doctype)
|
||||
@ -678,9 +678,6 @@ def get_children(doctype, parent, company, is_root=False):
|
||||
and `company` = %s and docstatus<2
|
||||
order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype),
|
||||
company, as_dict=1)
|
||||
|
||||
if parent=="Accounts":
|
||||
sort_root_accounts(acc)
|
||||
else:
|
||||
# other
|
||||
fields = ", account_currency" if doctype=="Account" else ""
|
||||
@ -693,6 +690,7 @@ def get_children(doctype, parent, company, is_root=False):
|
||||
parent, as_dict=1)
|
||||
|
||||
if doctype == 'Account':
|
||||
sort_accounts(acc, is_root, key="value")
|
||||
company_currency = frappe.db.get_value("Company", company, "default_currency")
|
||||
for each in acc:
|
||||
each["company_currency"] = company_currency
|
||||
|
Loading…
x
Reference in New Issue
Block a user