Added indexes for lft, rgt on nestedset doctypes (#13420)
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index ac19690..3d03d9d 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -273,4 +273,8 @@
def get_name_with_number(new_account, account_number):
if account_number and not new_account[0].isdigit():
new_account = account_number + " - " + new_account
- return new_account
\ No newline at end of file
+ return new_account
+
+
+def on_doctype_update():
+ frappe.db.add_index("Account", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py
index 55388a5..fe1e907 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.py
+++ b/erpnext/accounts/doctype/cost_center/cost_center.py
@@ -64,3 +64,6 @@
if not merge:
frappe.db.set_value("Cost Center", newdn, "cost_center_name",
" - ".join(newdn.split(" - ")[:-1]))
+
+def on_doctype_update():
+ frappe.db.add_index("Cost Center", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.py b/erpnext/agriculture/doctype/land_unit/land_unit.py
index 42a9b33..f577eca 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.py
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.py
@@ -177,4 +177,7 @@
# return nodes
return land_units
-
\ No newline at end of file
+
+
+def on_doctype_update():
+ frappe.db.add_index("Land Unit", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py
index bb12231..864d435 100755
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -329,4 +329,8 @@
.format(company=company, condition=condition), as_dict=1)
# return employee
- return employee
\ No newline at end of file
+ return employee
+
+
+def on_doctype_update():
+ frappe.db.add_index("Employee", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 92b3338..f829041 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -515,3 +515,4 @@
erpnext.patches.v10_0.set_student_party_type
erpnext.patches.v10_0.update_project_in_sle
erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract
+erpnext.patches.v11_0.add_index_on_nestedset_doctypes
\ No newline at end of file
diff --git a/erpnext/patches/v11_0/add_index_on_nestedset_doctypes.py b/erpnext/patches/v11_0/add_index_on_nestedset_doctypes.py
new file mode 100644
index 0000000..fde1891
--- /dev/null
+++ b/erpnext/patches/v11_0/add_index_on_nestedset_doctypes.py
@@ -0,0 +1,8 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+
+def execute():
+ for dt in ("Account", "Cost Center", "File", "Employee", "Land Unit", "Task", "Customer Group", "Sales Person", "Territory"):
+ frappe.get_doc("DocType", dt).run_module_method("on_doctype_update")
\ No newline at end of file
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index e418845..fcaa344 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -236,3 +236,6 @@
new_doc['subject'] = d.get("subject")
new_task = frappe.get_doc(new_doc)
new_task.insert()
+
+def on_doctype_update():
+ frappe.db.add_index("Task", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/setup/doctype/customer_group/customer_group.py b/erpnext/setup/doctype/customer_group/customer_group.py
index 7472c51..388ddca 100644
--- a/erpnext/setup/doctype/customer_group/customer_group.py
+++ b/erpnext/setup/doctype/customer_group/customer_group.py
@@ -25,3 +25,6 @@
return frappe.db.sql("""select name from `tabCustomer Group`
where lft <= %s and rgt >= %s
order by lft asc""", (lft, rgt), as_dict=True)
+
+def on_doctype_update():
+ frappe.db.add_index("Customer Group", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py
index 8542c88..816ee84 100644
--- a/erpnext/setup/doctype/sales_person/sales_person.py
+++ b/erpnext/setup/doctype/sales_person/sales_person.py
@@ -33,3 +33,6 @@
if sales_person and sales_person != self.name:
frappe.throw(_("Another Sales Person {0} exists with the same Employee id").format(sales_person))
+
+def on_doctype_update():
+ frappe.db.add_index("Sales Person", ["lft", "rgt"])
\ No newline at end of file
diff --git a/erpnext/setup/doctype/territory/territory.py b/erpnext/setup/doctype/territory/territory.py
index de8da35..095bd1c 100644
--- a/erpnext/setup/doctype/territory/territory.py
+++ b/erpnext/setup/doctype/territory/territory.py
@@ -22,3 +22,5 @@
super(Territory, self).on_update()
self.validate_one_root()
+def on_doctype_update():
+ frappe.db.add_index("Territory", ["lft", "rgt"])
\ No newline at end of file