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
|
2014-02-14 10:17:51 +00:00
|
|
|
import frappe
|
2012-04-17 07:10:37 +00:00
|
|
|
|
2012-12-12 10:56:39 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
@frappe.whitelist()
|
2012-04-17 07:10:37 +00:00
|
|
|
def get_children():
|
2014-02-14 10:17:51 +00:00
|
|
|
ctype = frappe.local.form_dict.get('ctype')
|
|
|
|
frappe.local.form_dict['parent_field'] = 'parent_' + ctype.lower().replace(' ', '_')
|
|
|
|
if not frappe.form_dict.get('parent'):
|
|
|
|
frappe.local.form_dict['parent'] = ''
|
2012-12-12 10:56:39 +00:00
|
|
|
|
2014-02-26 07:05:33 +00:00
|
|
|
return frappe.db.sql("""select name as value,
|
2012-04-17 07:10:37 +00:00
|
|
|
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"
|
2014-02-14 10:17:51 +00:00
|
|
|
order by name""" % frappe.local.form_dict, as_dict=1)
|
2012-04-17 07:10:37 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
@frappe.whitelist()
|
2012-04-17 07:10:37 +00:00
|
|
|
def add_node():
|
2014-03-27 12:21:41 +00:00
|
|
|
# ctype = frappe.form_dict.get('ctype')
|
2012-04-17 07:10:37 +00:00
|
|
|
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,
|
2014-02-14 10:17:51 +00:00
|
|
|
name_field: frappe.form_dict['name_field'],
|
|
|
|
parent_field: frappe.form_dict['parent'],
|
|
|
|
"is_group": frappe.form_dict['is_group']
|
2013-01-24 09:27:43 +00:00
|
|
|
}]
|
2013-07-22 11:45:01 +00:00
|
|
|
if ctype == "Sales Person":
|
2014-02-14 10:17:51 +00:00
|
|
|
doclist[0]["employee"] = frappe.form_dict.get('employee')
|
2013-07-22 11:45:01 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.bean(doclist).save()
|