2012-07-19 08:10:31 +00:00
|
|
|
from __future__ import unicode_literals
|
2012-04-17 07:10:37 +00:00
|
|
|
import webnotes
|
|
|
|
|
2012-12-12 10:56:39 +00:00
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_children():
|
|
|
|
ctype = webnotes.form_dict.get('ctype')
|
|
|
|
webnotes.form_dict['parent_field'] = 'parent_' + ctype.lower().replace(' ', '_')
|
2012-12-12 10:56:39 +00:00
|
|
|
if not webnotes.form_dict.get('parent'):
|
|
|
|
webnotes.form_dict['parent'] = ''
|
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
return webnotes.conn.sql("""select name as value,
|
|
|
|
if(is_group='Yes', 1, 0) as expandable
|
|
|
|
from `tab%(ctype)s`
|
|
|
|
where docstatus < 2
|
2013-01-09 11:09:27 +00:00
|
|
|
and ifnull(%(parent_field)s,'') = "%(parent)s"
|
2012-04-17 07:10:37 +00:00
|
|
|
order by name""" % webnotes.form_dict, as_dict=1)
|
|
|
|
|
|
|
|
@webnotes.whitelist()
|
|
|
|
def add_node():
|
2013-01-24 09:27:43 +00:00
|
|
|
# from webnotes.model.doc import Document
|
2012-04-17 07:10:37 +00:00
|
|
|
ctype = webnotes.form_dict.get('ctype')
|
|
|
|
parent_field = 'parent_' + ctype.lower().replace(' ', '_')
|
2013-01-24 09:27:43 +00:00
|
|
|
name_field = ctype.lower().replace(' ', '_') + '_name'
|
|
|
|
|
|
|
|
doclist = [{
|
|
|
|
"doctype": ctype,
|
|
|
|
"__islocal": 1,
|
|
|
|
name_field: webnotes.form_dict['name_field'],
|
|
|
|
parent_field: webnotes.form_dict['parent'],
|
|
|
|
"is_group": webnotes.form_dict['is_group']
|
|
|
|
}]
|
2013-07-22 11:45:01 +00:00
|
|
|
if ctype == "Sales Person":
|
|
|
|
doclist[0]["employee"] = webnotes.form_dict.get('employee')
|
|
|
|
|
2013-02-18 12:54:28 +00:00
|
|
|
webnotes.bean(doclist).save()
|