fix(set_serial_no_status): auto commit on many writes (#21845)
diff --git a/erpnext/patches/v12_0/set_serial_no_status.py b/erpnext/patches/v12_0/set_serial_no_status.py
index 4ec84ef..abba37d 100644
--- a/erpnext/patches/v12_0/set_serial_no_status.py
+++ b/erpnext/patches/v12_0/set_serial_no_status.py
@@ -5,8 +5,12 @@
def execute():
frappe.reload_doc('stock', 'doctype', 'serial_no')
- for serial_no in frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date from `tabSerial No`
- where (status is NULL OR status='')""", as_dict = 1):
+ serial_no_list = frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date from `tabSerial No`
+ where (status is NULL OR status='')""", as_dict = 1)
+ if len(serial_no_list) > 20000:
+ frappe.db.auto_commit_on_many_writes = True
+
+ for serial_no in serial_no_list:
if serial_no.get("delivery_document_type"):
status = "Delivered"
elif serial_no.get("warranty_expiry_date") and getdate(serial_no.get("warranty_expiry_date")) <= getdate(nowdate()):
@@ -14,4 +18,7 @@
else:
status = "Active"
- frappe.db.set_value("Serial No", serial_no.get("name"), "status", status)
\ No newline at end of file
+ frappe.db.set_value("Serial No", serial_no.get("name"), "status", status)
+
+ if frappe.db.auto_commit_on_many_writes:
+ frappe.db.auto_commit_on_many_writes = False