I’ve tried using frappe.get_doc().cancel() but it didn’t work.
je_doc = frappe.get_doc('Journal Entry', 'abc')
je_doc.cancel()
pr = frappe.get_doc('Purchase Receipt', {
'po_reference': data['params']['inbound_reference']})
pr.cancel()
pr.save(ignore_permissions=True)
frappe.db.commit()
I’ve done this before but still can’t answer my issue
Have you tried removing this line:
pr.save(ignore_permissions=True)
Also, are you getting any error messages in the logs? There might be documents related to the Purchase Receipt that are restricting the cancellation.
I dont use ignore_permissions=True before.
And in my case i think, this is securty/permission issues. because an API would known as Guest in ERPNext. and Guest can’t cancel a document.
or like you’ve said, maybe Purchase Receipt has restricted method to cancellation.
Also, i dont getting any error messages in the logs.
Thanks for answering. Appreciate that.
Exactly as i thought.
when you receive a request from a webhook. and would like to change document either cancelling or deleting a document. ERPNext will assume that the request is “Guest” and with “Guest Role”.
You can change Guest Role in “Role List”. and allow DocType that you would like to cancel/delete.
Giving anonymous users permission to cancel and delete is a huge security risk. In most circumstances, amuch better option will be to use some kind of authentication.
You’re right, Thanks for your suggestion.
I will work for the authentication now.
I am using the token based authentication to cancel submitted entry. There was nothing in the ERPNext doc to which API endpoint should I use to do it. I tried PUT /api/resource/:docType/:name with data = {‘docstatus’: 2} but got internal server error. Can you help me out in this?