Stop deleting attchments

Hi,

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 hooks.py
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?

Regards
Ruchin Sharma