mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-22 19:55:29 +00:00
perf: Batch GLE/SLE rename commits (#47950)
(cherry picked from commit bb693c0a4f)
Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
@@ -7,7 +7,7 @@ from frappe import _
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
from frappe.model.naming import set_name_from_naming_options
|
from frappe.model.naming import set_name_from_naming_options
|
||||||
from frappe.utils import flt, fmt_money, now
|
from frappe.utils import create_batch, flt, fmt_money, now
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
@@ -451,12 +451,15 @@ def rename_gle_sle_docs():
|
|||||||
def rename_temporarily_named_docs(doctype):
|
def rename_temporarily_named_docs(doctype):
|
||||||
"""Rename temporarily named docs using autoname options"""
|
"""Rename temporarily named docs using autoname options"""
|
||||||
docs_to_rename = frappe.get_all(doctype, {"to_rename": "1"}, order_by="creation", limit=50000)
|
docs_to_rename = frappe.get_all(doctype, {"to_rename": "1"}, order_by="creation", limit=50000)
|
||||||
for doc in docs_to_rename:
|
autoname = frappe.get_meta(doctype).autoname
|
||||||
oldname = doc.name
|
|
||||||
set_name_from_naming_options(frappe.get_meta(doctype).autoname, doc)
|
for batch in create_batch(docs_to_rename, 100):
|
||||||
newname = doc.name
|
for doc in batch:
|
||||||
frappe.db.sql(
|
oldname = doc.name
|
||||||
f"UPDATE `tab{doctype}` SET name = %s, to_rename = 0, modified = %s where name = %s",
|
set_name_from_naming_options(autoname, doc)
|
||||||
(newname, now(), oldname),
|
newname = doc.name
|
||||||
auto_commit=True,
|
frappe.db.sql(
|
||||||
)
|
f"UPDATE `tab{doctype}` SET name = %s, to_rename = 0, modified = %s where name = %s",
|
||||||
|
(newname, now(), oldname),
|
||||||
|
)
|
||||||
|
frappe.db.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user