[enhancement] sort root accounts as assets, liability, equty, income, expense

This commit is contained in:
Rushabh Mehta 2015-04-29 12:25:18 +05:30
parent 081935eff7
commit 0590cdceab
2 changed files with 25 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import frappe
import frappe.defaults
from frappe.utils import flt
from erpnext.accounts.utils import get_balance_on
from erpnext.accounts.report.financial_statements import sort_root_accounts
@frappe.whitelist()
def get_companies():
@ -21,12 +22,15 @@ def get_children():
# root
if args['parent'] in ("Accounts", "Cost Centers"):
acc = frappe.db.sql(""" select
name as value, is_group as expandable
name as value, is_group as expandable, root_type, report_type
from `tab%s`
where ifnull(parent_%s,'') = ''
and `company` = %s and docstatus<2
order by name""" % (ctype, ctype.lower().replace(' ','_'), '%s'),
company, as_dict=1)
if args["parent"]=="Accounts":
sort_root_accounts(acc)
else:
# other
acc = frappe.db.sql("""select

View File

@ -184,9 +184,14 @@ def filter_accounts(accounts, depth=10):
parent_children_map.setdefault(d.parent_account or None, []).append(d)
filtered_accounts = []
def add_to_list(parent, level):
if level < depth:
for child in (parent_children_map.get(parent) or []):
children = parent_children_map.get(parent) or []
if parent == None:
sort_root_accounts(children)
for child in children:
child.indent = level
filtered_accounts.append(child)
add_to_list(child.name, level + 1)
@ -203,6 +208,20 @@ def filter_accounts(accounts, depth=10):
return filtered_accounts, accounts_by_name
def sort_root_accounts(roots):
"""Sort root types as Asset, Liability, Equity, Income, Expense"""
def compare_roots(a, b):
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":
return -1
if a.root_type == "Liability" and b.root_type == "Equity":
return -1
return 1
roots.sort(compare_roots)
def get_gl_entries(company, from_date, to_date, root_lft, root_rgt, ignore_closing_entries=False):
"""Returns a dict like { "account": [gl entries], ... }"""
additional_conditions = []