brotherton-erpnext/erpnext/patches/v11_0/update_department_lft_rgt.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
637 B
Python
Raw Normal View History

2018-11-06 11:02:29 +00:00
from __future__ import unicode_literals
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')):
2018-05-29 10:47:06 +00:00
frappe.get_doc({
'doctype': 'Department',
'department_name': _('All Departments'),
'is_group': 1
2018-09-03 10:36:22 +00:00
}).insert(ignore_permissions=True, ignore_mandatory=True)
frappe.db.sql("""update `tabDepartment` set parent_department = '{0}'
where is_group = 0""".format(_('All Departments')))
rebuild_tree("Department", "parent_department")