49 lines
1.5 KiB
Python
Raw Normal View History

2012-04-13 19:04:55 +05:30
import webnotes
2012-05-22 16:54:46 +05:30
from webnotes.utils import get_defaults, cstr
2012-04-13 19:04:55 +05:30
@webnotes.whitelist()
def get_companies():
return [r[0] for r in webnotes.conn.sql("""select name from tabCompany where docstatus!=2""")]
@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
2012-05-22 16:54:46 +05:30
company_field = ctype=='Account' and 'company' or 'company_name'
2012-04-13 19:04:55 +05:30
# root
2012-05-22 16:54:46 +05:30
if args['parent'] == company:
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,'') = ''
2012-05-22 16:54:46 +05:30
and %s = %s and docstatus<2
2012-04-13 19:04:55 +05:30
order by name""" % (ctype, ctype.lower().replace(' ','_'), company_field, '%s'),
args['parent'], 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:
bal = webnotes.conn.sql("select balance from `tabAccount Balance` \
2012-08-09 16:24:20 +05:30
where account = %s and period = %s", (each.get('value'), get_defaults('fiscal_year')))
bal = bal and bal[0][0] or 0
2012-05-22 16:54:46 +05:30
each['balance'] = currency + ' ' + cstr(bal)
return acc
2012-04-13 19:04:55 +05:30
2012-05-22 16:54:46 +05:30
@webnotes.whitelist()
def get_account_balance():
args = webnotes.form_dict
acc = args['acc']
return 'Rs. 100'