Stop deleting attchments


By using using I was trying to stop the use to delete any attachment from item doctype, if Item doctype is in Approved state.

Below is my code for the same:

def check_doc_status(doc, method=None):
    if doc.attached_to_doctype == "Item":
        doc_m = frappe.get_doc("Item", doc.attached_to_name)
        if doc_m.workflow_state == "Approved":
            frappe.throw("You cannot attach/delete file to this item, since the item is in Approved State.")

I m using on_trash trigger in
But the issue is, it gives the error message and shows the attachment there only but the physical file get deleted.

Any idea, how can overcome this issue?

Ruchin Sharma

@ruchin78 hi ,I am trying to do the same my scenario is on sales order there is a attach field pdc user will attach the file after submit but how to restrict them for deletion for the file once it get attached…please help any suggestion/guidance will be helpful.