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