commit
b6a1bcc730
@ -6,6 +6,7 @@ import frappe
|
|||||||
import frappe.defaults
|
import frappe.defaults
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
from erpnext.accounts.utils import get_balance_on
|
from erpnext.accounts.utils import get_balance_on
|
||||||
|
from erpnext.accounts.report.financial_statements import sort_root_accounts
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_companies():
|
def get_companies():
|
||||||
@ -21,12 +22,15 @@ def get_children():
|
|||||||
# root
|
# root
|
||||||
if args['parent'] in ("Accounts", "Cost Centers"):
|
if args['parent'] in ("Accounts", "Cost Centers"):
|
||||||
acc = frappe.db.sql(""" select
|
acc = frappe.db.sql(""" select
|
||||||
name as value, if(group_or_ledger='Group', 1, 0) as expandable
|
name as value, if(group_or_ledger='Group', 1, 0) as expandable, root_type, report_type
|
||||||
from `tab%s`
|
from `tab%s`
|
||||||
where ifnull(parent_%s,'') = ''
|
where ifnull(parent_%s,'') = ''
|
||||||
and `company` = %s and docstatus<2
|
and `company` = %s and docstatus<2
|
||||||
order by name""" % (ctype, ctype.lower().replace(' ','_'), '%s'),
|
order by name""" % (ctype, ctype.lower().replace(' ','_'), '%s'),
|
||||||
company, as_dict=1)
|
company, as_dict=1)
|
||||||
|
|
||||||
|
if args["parent"]=="Accounts":
|
||||||
|
sort_root_accounts(acc)
|
||||||
else:
|
else:
|
||||||
# other
|
# other
|
||||||
acc = frappe.db.sql("""select
|
acc = frappe.db.sql("""select
|
||||||
|
@ -186,7 +186,10 @@ def filter_accounts(accounts, depth=10):
|
|||||||
filtered_accounts = []
|
filtered_accounts = []
|
||||||
def add_to_list(parent, level):
|
def add_to_list(parent, level):
|
||||||
if level < depth:
|
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
|
child.indent = level
|
||||||
filtered_accounts.append(child)
|
filtered_accounts.append(child)
|
||||||
add_to_list(child.name, level + 1)
|
add_to_list(child.name, level + 1)
|
||||||
@ -203,6 +206,22 @@ def filter_accounts(accounts, depth=10):
|
|||||||
|
|
||||||
return filtered_accounts, accounts_by_name
|
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
|
||||||
|
if a.root_type == "Income" and b.root_type == "Expense":
|
||||||
|
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):
|
def get_gl_entries(company, from_date, to_date, root_lft, root_rgt, ignore_closing_entries=False):
|
||||||
"""Returns a dict like { "account": [gl entries], ... }"""
|
"""Returns a dict like { "account": [gl entries], ... }"""
|
||||||
additional_conditions = []
|
additional_conditions = []
|
||||||
|
@ -123,7 +123,8 @@ def accumulate_values_into_parents(accounts, accounts_by_name):
|
|||||||
def prepare_data(accounts, filters, total_row):
|
def prepare_data(accounts, filters, total_row):
|
||||||
show_zero_values = cint(filters.show_zero_values)
|
show_zero_values = cint(filters.show_zero_values)
|
||||||
data = []
|
data = []
|
||||||
for i, d in enumerate(accounts):
|
accounts_with_zero_value = []
|
||||||
|
for d in accounts:
|
||||||
has_value = False
|
has_value = False
|
||||||
row = {
|
row = {
|
||||||
"account_name": d.account_name,
|
"account_name": d.account_name,
|
||||||
@ -141,7 +142,12 @@ def prepare_data(accounts, filters, total_row):
|
|||||||
if row[key]:
|
if row[key]:
|
||||||
has_value = True
|
has_value = True
|
||||||
|
|
||||||
if has_value or show_zero_values:
|
if show_zero_values:
|
||||||
|
data.append(row)
|
||||||
|
else:
|
||||||
|
if not has_value:
|
||||||
|
accounts_with_zero_value.append(d.name)
|
||||||
|
elif d.parent_account not in accounts_with_zero_value:
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
data.extend([{},total_row])
|
data.extend([{},total_row])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user