brotherton-erpnext/erpnext/patches/v11_0/update_department_lft_rgt.py
Shreya Shah 6bf4e5b73b Department Tree (#13567)
* Department Tree

* print hide fields

* create 'All Departments' as parent on setup

* patch to set lft rgt

* fix translatable string
2018-04-13 15:09:26 +05:30

19 lines
574 B
Python

import frappe
from frappe import _
from frappe.utils.nestedset import rebuild_tree
def execute():
""" assign lft and rgt appropriately """
frappe.reload_doc("hr", "doctype", "department")
if not frappe.db.exists("Department", _('All Departments')):
frappe.get_doc({
'doctype': 'Department',
'department_name': _('All Departments'),
'is_group': 1
}).insert(ignore_permissions=True)
frappe.db.sql("""update `tabDepartment` set parent_department = '{0}'
where is_group = 0""".format(_('All Departments')))
rebuild_tree("Department", "parent_department")