2015-03-03 14:55:30 +05:30
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 14:59:54 +05:30
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2012-07-19 13:40:31 +05:30
|
|
|
from __future__ import unicode_literals
|
2014-02-14 15:47:51 +05:30
|
|
|
import frappe
|
2012-04-17 12:40:37 +05:30
|
|
|
|
2012-12-12 16:26:39 +05:30
|
|
|
|
2014-02-14 15:47:51 +05:30
|
|
|
@frappe.whitelist()
|
2012-04-17 12:40:37 +05:30
|
|
|
def get_children():
|
2014-02-14 15:47:51 +05:30
|
|
|
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'] = ''
|
2014-04-22 18:54:54 +05:30
|
|
|
|
|
|
|
return frappe.db.sql("""select name as value,
|
2012-04-17 12:40:37 +05:30
|
|
|
if(is_group='Yes', 1, 0) as expandable
|
|
|
|
from `tab%(ctype)s`
|
|
|
|
where docstatus < 2
|
2013-01-09 16:39:27 +05:30
|
|
|
and ifnull(%(parent_field)s,'') = "%(parent)s"
|
2014-02-14 15:47:51 +05:30
|
|
|
order by name""" % frappe.local.form_dict, as_dict=1)
|
2014-04-22 18:54:54 +05:30
|
|
|
|
2014-02-14 15:47:51 +05:30
|
|
|
@frappe.whitelist()
|
2012-04-17 12:40:37 +05:30
|
|
|
def add_node():
|
2014-04-22 18:54:54 +05:30
|
|
|
ctype = frappe.form_dict.get('ctype')
|
2012-04-17 12:40:37 +05:30
|
|
|
parent_field = 'parent_' + ctype.lower().replace(' ', '_')
|
2013-01-24 14:57:43 +05:30
|
|
|
name_field = ctype.lower().replace(' ', '_') + '_name'
|
2014-04-22 18:54:54 +05:30
|
|
|
|
|
|
|
doc = frappe.new_doc(ctype)
|
|
|
|
doc.update({
|
2014-02-14 15:47:51 +05:30
|
|
|
name_field: frappe.form_dict['name_field'],
|
|
|
|
parent_field: frappe.form_dict['parent'],
|
|
|
|
"is_group": frappe.form_dict['is_group']
|
2014-04-22 18:54:54 +05:30
|
|
|
})
|
2013-07-22 17:15:01 +05:30
|
|
|
if ctype == "Sales Person":
|
2014-04-22 18:54:54 +05:30
|
|
|
doc.employee = frappe.form_dict.get('employee')
|
|
|
|
|
|
|
|
doc.save()
|