Hi,
Can anyone assist? Is there an alternative way to perform bulk deletion?
I have 20K+ submitted delivery note records, and deleting them through the UI is complex.
You can delete them by turning list view into report view and cancel them first if submitted.
The Report view handles database stuff more fast than the list view. The deletion by SQL query is not advisable.
Can you code in bench console to solve this issue, undoubtedly this is the best method for solving the problem using this code for delete in bulk
import frappe
doctype = "Delivery Note"
delivery_notes = frappe.get_all(doctype, filters={"docstatus": 1}, fields=["name"])
for dn in delivery_notes:
try:
doc = frappe.get_doc(doctype, dn.name)
doc.cancel()
doc.delete()
frappe.db.commit()
print(f"Deleted: {dn.name}")
except Exception as e:
print(f"Error deleting {dn.name}: {e}")
-
This script cancel all submitted Delivery Notes and then removes them.
-
It ensures data integrity when doing the mass deletes.
-
Use with care or may remove important data.