chore: Use sql to set naming series in older projects (#24512)

* chore: Use sql to set naming series in older projects

* fix: Remove unncessary db.commit()
This commit is contained in:
Marica 2021-02-01 20:05:29 +05:30 committed by GitHub
parent 77d5f59376
commit fb016edb7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 19 deletions

View File

@ -749,4 +749,4 @@ erpnext.patches.v13_0.update_project_template_tasks
erpnext.patches.v13_0.set_company_in_leave_ledger_entry erpnext.patches.v13_0.set_company_in_leave_ledger_entry
erpnext.patches.v13_0.convert_qi_parameter_to_link_field 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.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

View File

@ -4,23 +4,10 @@ from frappe.custom.doctype.property_setter.property_setter import make_property_
def execute(): def execute():
frappe.reload_doc("projects", "doctype", "project") 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 frappe.db.sql("""UPDATE `tabProject`
# (to bypass 'Cant change naming series' validation on save) SET
make_property_setter("Project", "naming_series", "set_only_once", 0, "Check") 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()