improv department tree

This commit is contained in:
Zlash65 2018-04-18 18:13:24 +05:30
parent 366ca92ba7
commit 39668609ce
2 changed files with 45 additions and 2 deletions

View File

@ -21,4 +21,23 @@ class Department(NestedSet):
delete_events(self.doctype, self.name)
def on_doctype_update():
frappe.db.add_index("Department", ["lft", "rgt"])
frappe.db.add_index("Department", ["lft", "rgt"])
@frappe.whitelist()
def get_children(doctype, parent=None, company=None, is_root=False):
condition = ''
if company == parent:
condition = 'name="All Departments"'
elif company:
condition = "parent_department='{0}' and company='{1}'".format(parent, company)
else:
condition = "parent_department = '{0}'".format(parent)
return frappe.db.sql("""
select
name as value,
is_group as expandable
from `tab{doctype}`
where
{condition}
order by name""".format(doctype=doctype, condition=condition), as_dict=1)

View File

@ -1,3 +1,27 @@
frappe.treeview_settings["Department"] = {
ignore_fields:["parent_department"]
ignore_fields:["parent_department"],
get_tree_nodes: 'erpnext.hr.doctype.department.department.get_children',
filters: [
{
fieldname: "company",
fieldtype:"Link",
options: "Company",
label: __("Company"),
},
],
breadcrumb: "HR",
root_label: "All Departments",
get_tree_root: true,
menu_items: [
{
label: __("New Department"),
action: function() {
frappe.new_doc("Department", true);
},
condition: 'frappe.boot.user.can_create.indexOf("Department") !== -1'
}
],
onload: function(treeview) {
treeview.make_tree();
}
};