By Silas Kwarteng on December 11, 2024
Beginner

How to bulk delete Repostings on ERPNext


--> To delete repostings on erpnext, you first


--> Enable scheduler


--> Open System Console


--> Check the commit radio button


then you need to cancel all repostings before you can proceed to deleting them so (exercise caution with this command)


--> To cancel, use the below command:


# Cancel all queued and in-progress reposts in one operation

frappe.db.set_value('Repost Item Valuation',

   {'status': ['in', ['Queued', 'In Progress']]},

   {'docstatus': 2, 'status': 'Cancelled'},

   update_modified=False

)

frappe.db.commit()


# log(name)


--> Click on execute to run the command.


 



Use below command to Delete for Specific Invoices:


Note: All you need to do is to change the filters ie. status, voucher\_no as shown below: 

# Get all Repost Item Valuation documents in queued state


in\_progress = frappe.db.get\_list('Repost Item Valuation', filters={'status': 'in progress', 'voucher\_no': '20230813184152821301'}, fields=['name'])


# Iterate through each queued document and cancel if the voucher number matches


for doc in in\_progress:


name = doc.get('name')


frappe.db.set\_value('Repost Item Valuation', name, 'docstatus', 2)


 



--> Now, the next step is to delete the repostings. To do that, we run the below commands:


batch\_size = 500


doc = frappe.db.get\_list('Repost Item Valuation',['name'],limit\_page\_length=batch\_size)


for docname in doc:


name = docname.get('name')


# log(name)


frappe.delete\_doc('Repost Item Valuation', name)


Note: This delete command can't work for extremely high numbers of reposting. You can tune the batch size until it works for you. 

 


More articles on Erpnext



More articles on Erpnext
Comments

No comments yet.

Add a comment
Ctrl+Enter to add comment