improv department tree
diff --git a/erpnext/hr/doctype/department/department.py b/erpnext/hr/doctype/department/department.py
index fda1b69..f1e0aee 100644
--- a/erpnext/hr/doctype/department/department.py
+++ b/erpnext/hr/doctype/department/department.py
@@ -21,4 +21,23 @@
 		delete_events(self.doctype, self.name)
 
 def on_doctype_update():
-	frappe.db.add_index("Department", ["lft", "rgt"])
\ No newline at end of file
+	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)
diff --git a/erpnext/hr/doctype/department/department_tree.js b/erpnext/hr/doctype/department/department_tree.js
index 5652ad6..1f891fd 100644
--- a/erpnext/hr/doctype/department/department_tree.js
+++ b/erpnext/hr/doctype/department/department_tree.js
@@ -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();
+	}
 };
\ No newline at end of file