ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Purchase Order Delete V13

HI Guys,
I wrote a server script scheduled to run every hour on purchase order doctype. For some reason, it executes proper and can still see some doc’s that are meant to be deleted on desk. When i try to get the doc from the console by its name, it says “Purchase Order OHL-PO-00023 not found”

from datetime import datetime
doc = frappe.get_all("Purchase Order", filters={"status":"Draft"})
for d in doc:
    doc_date = frappe.get_doc("Purchase Order",d.name)
    if (datetime.now().day - doc_date.creation.day) >= 29:
        # doc_date.del
        doc_date.delete()