brotherton-erpnext/erpnext/accounts/page/accounts_browser/accounts_browser.py

48 lines
1.4 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
2014-02-14 10:17:51 +00:00
import frappe
import frappe.defaults
from frappe.utils import flt
from erpnext.accounts.utils import get_balance_on
2012-04-13 13:34:55 +00:00
2014-02-14 10:17:51 +00:00
@frappe.whitelist()
2012-04-13 13:34:55 +00:00
def get_companies():
"""get a list of companies based on permission"""
return [d.name for d in frappe.get_list("Company", fields=["name"],
order_by="name")]
2012-12-05 08:57:50 +00:00
2014-02-14 10:17:51 +00:00
@frappe.whitelist()
2012-04-13 13:34:55 +00:00
def get_children():
2014-02-14 10:17:51 +00:00
args = frappe.local.form_dict
2012-05-22 11:24:46 +00:00
ctype, company = args['ctype'], args['comp']
2012-04-13 13:34:55 +00:00
# root
2013-06-24 10:13:18 +00:00
if args['parent'] in ("Accounts", "Cost Centers"):
acc = frappe.db.sql(""" select
2012-04-13 13:34:55 +00:00
name as value, if(group_or_ledger='Group', 1, 0) as expandable
from `tab%s`
where ifnull(parent_%s,'') = ''
and `company` = %s and docstatus<2
order by name""" % (ctype, ctype.lower().replace(' ','_'), '%s'),
2013-06-24 10:13:18 +00:00
company, as_dict=1)
else:
2012-05-22 11:24:46 +00:00
# other
acc = frappe.db.sql("""select
2012-05-22 11:24:46 +00:00
name as value, if(group_or_ledger='Group', 1, 0) as expandable
from `tab%s`
2012-05-22 11:24:46 +00:00
where ifnull(parent_%s,'') = %s
and docstatus<2
2012-05-22 11:24:46 +00:00
order by name""" % (ctype, ctype.lower().replace(' ','_'), '%s'),
args['parent'], as_dict=1)
2012-05-22 11:24:46 +00:00
if ctype == 'Account':
2014-02-26 07:05:33 +00:00
currency = frappe.db.sql("select default_currency from `tabCompany` where name = %s", company)[0][0]
2012-05-22 11:24:46 +00:00
for each in acc:
bal = get_balance_on(each.get("value"))
each["currency"] = currency
each["balance"] = flt(bal)
2012-05-22 11:24:46 +00:00
return acc