2018-04-13 09:39:26 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _
|
|
|
|
from frappe.utils.nestedset import rebuild_tree
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-04-13 09:39:26 +00:00
|
|
|
def execute():
|
|
|
|
"""assign lft and rgt appropriately"""
|
2022-06-27 14:55:16 +00:00
|
|
|
frappe.reload_doc("setup", "doctype", "department")
|
2018-04-13 09:39:26 +00:00
|
|
|
if not frappe.db.exists("Department", _("All Departments")):
|
2018-05-29 10:47:06 +00:00
|
|
|
frappe.get_doc(
|
2018-04-13 09:39:26 +00:00
|
|
|
{"doctype": "Department", "department_name": _("All Departments"), "is_group": 1}
|
2018-09-03 10:36:22 +00:00
|
|
|
).insert(ignore_permissions=True, ignore_mandatory=True)
|
2018-04-13 09:39:26 +00:00
|
|
|
|
|
|
|
frappe.db.sql(
|
|
|
|
"""update `tabDepartment` set parent_department = '{0}'
|
|
|
|
where is_group = 0""".format(
|
|
|
|
_("All Departments")
|
2022-03-28 13:22:46 +00:00
|
|
|
)
|
|
|
|
)
|
2018-04-13 09:39:26 +00:00
|
|
|
|
|
|
|
rebuild_tree("Department", "parent_department")
|