chore: Use sql to set naming series in older projects (#24513)
* chore: Use sql to set naming series in older projects
* fix: Remove unncessary db.commit()
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index f3660b3..9e022da 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -747,4 +747,4 @@
erpnext.patches.v13_0.set_company_in_leave_ledger_entry
erpnext.patches.v13_0.convert_qi_parameter_to_link_field
erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes
-erpnext.patches.v13_0.add_naming_series_to_old_projects
+erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021
diff --git a/erpnext/patches/v13_0/add_naming_series_to_old_projects.py b/erpnext/patches/v13_0/add_naming_series_to_old_projects.py
index 79b6753..5ed9040 100644
--- a/erpnext/patches/v13_0/add_naming_series_to_old_projects.py
+++ b/erpnext/patches/v13_0/add_naming_series_to_old_projects.py
@@ -4,23 +4,10 @@
def execute():
frappe.reload_doc("projects", "doctype", "project")
- projects = frappe.db.get_all("Project",
- fields=["name", "naming_series", "modified"],
- filters={
- "naming_series": ["is", "not set"]
- },
- order_by="timestamp(modified) asc")
- # disable set only once as the old docs must be saved
- # (to bypass 'Cant change naming series' validation on save)
- make_property_setter("Project", "naming_series", "set_only_once", 0, "Check")
+ frappe.db.sql("""UPDATE `tabProject`
+ SET
+ naming_series = 'PROJ-.####'
+ WHERE
+ naming_series is NULL""")
- for entry in projects:
- # need to save the doc so that users can edit old projects
- doc = frappe.get_doc("Project", entry.name)
- if not doc.naming_series:
- doc.naming_series = "PROJ-.####"
- doc.save()
-
- delete_property_setter("Project", "set_only_once", "naming_series")
- frappe.db.commit()