2013-08-05 14:59:54 +05:30
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2012-07-19 13:40:31 +05:30
|
|
|
from __future__ import unicode_literals
|
2012-04-13 19:04:55 +05:30
|
|
|
import webnotes
|
2013-02-19 15:27:31 +05:30
|
|
|
import webnotes.defaults
|
2013-03-13 12:53:00 +05:30
|
|
|
from webnotes.utils import flt
|
2012-09-28 16:03:11 +05:30
|
|
|
from accounts.utils import get_balance_on
|
2012-04-13 19:04:55 +05:30
|
|
|
|
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_companies():
|
2012-09-10 14:13:01 +05:30
|
|
|
"""get a list of companies based on permission"""
|
2013-08-05 16:21:04 +05:30
|
|
|
return [d.name for d in webnotes.get_list("Company", fields=["name"],
|
|
|
|
order_by="name")]
|
2012-12-05 14:27:50 +05:30
|
|
|
|
2012-04-13 19:04:55 +05:30
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_children():
|
|
|
|
args = webnotes.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"):
|
2012-05-22 16:54:46 +05:30
|
|
|
acc = webnotes.conn.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
|
|
|
|
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 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
|