brotherton-erpnext/erpnext/selling/page/sales_browser/sales_browser.py

38 lines
1.1 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
2014-02-14 10:17:51 +00:00
import frappe
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 get_children():
2014-02-14 10:17:51 +00:00
ctype = frappe.local.form_dict.get('ctype')
2015-11-17 12:57:50 +00:00
parent_field = 'parent_' + ctype.lower().replace(' ', '_')
parent = frappe.form_dict.get("parent") or ""
return frappe.db.sql("""select name as value,
2012-04-17 07:10:37 +00:00
if(is_group='Yes', 1, 0) as expandable
2015-11-17 12:57:50 +00:00
from `tab{ctype}`
2012-04-17 07:10:37 +00:00
where docstatus < 2
2015-11-17 12:57:50 +00:00
and ifnull(`{parent_field}`,'') = %s
order by name""".format(ctype=frappe.db.escape(ctype), parent_field=frappe.db.escape(parent_field)),
parent, as_dict=1)
2014-02-14 10:17:51 +00:00
@frappe.whitelist()
2012-04-17 07:10:37 +00:00
def add_node():
ctype = frappe.form_dict.get('ctype')
2012-04-17 07:10:37 +00:00
parent_field = 'parent_' + ctype.lower().replace(' ', '_')
name_field = ctype.lower().replace(' ', '_') + '_name'
doc = frappe.new_doc(ctype)
doc.update({
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']
})
if ctype == "Sales Person":
doc.employee = frappe.form_dict.get('employee')
doc.save()