2013-11-20 07:29:58 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2012-07-19 08:10:31 +00:00
|
|
|
from __future__ import unicode_literals
|
2012-04-13 13:34:55 +00:00
|
|
|
import webnotes
|
2013-02-19 09:57:31 +00:00
|
|
|
import webnotes.defaults
|
2013-03-13 07:23:00 +00:00
|
|
|
from webnotes.utils import flt
|
2012-09-28 10:33:11 +00:00
|
|
|
from accounts.utils import get_balance_on
|
2012-04-13 13:34:55 +00:00
|
|
|
|
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_companies():
|
2012-09-10 08:43:01 +00:00
|
|
|
"""get a list of companies based on permission"""
|
2013-08-05 10:51:04 +00:00
|
|
|
return [d.name for d in webnotes.get_list("Company", fields=["name"],
|
|
|
|
order_by="name")]
|
2012-12-05 08:57:50 +00:00
|
|
|
|
2012-04-13 13:34:55 +00:00
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_children():
|
2013-10-02 09:04:25 +00:00
|
|
|
args = webnotes.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"):
|
2012-05-22 11:24:46 +00:00
|
|
|
acc = webnotes.conn.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,'') = ''
|
2013-07-09 10:15:38 +00:00
|
|
|
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)
|
2012-05-22 11:24:46 +00:00
|
|
|
else:
|
|
|
|
# other
|
|
|
|
acc = webnotes.conn.sql("""select
|
|
|
|
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':
|
|
|
|
currency = webnotes.conn.sql("select default_currency from `tabCompany` where name = %s", company)[0][0]
|
|
|
|
for each in acc:
|
2012-09-28 10:33:11 +00:00
|
|
|
bal = get_balance_on(each.get("value"))
|
2013-03-13 07:23:00 +00:00
|
|
|
each["currency"] = currency
|
|
|
|
each["balance"] = flt(bal)
|
2012-05-22 11:24:46 +00:00
|
|
|
|
|
|
|
return acc
|