def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reload=False, ignore_permissions=False, flags=None, ignore_on_trash=False):
 if (not ignore_doctypes):
  ignore_doctypes = []
 if (not doctype):
  doctype = frappe.form_dict.get(u'dt')
  name = frappe.form_dict.get(u'dn')
 names = name
 if isinstance(name, basestring):
  names = [name]
 for name in (names or []):
  if (not frappe.db.exists(doctype, name)):
   return
  delete_all_passwords_for(doctype, name)
  doc = None
  if (doctype == u'DocType'):
   if for_reload:
    try:
     doc = frappe.get_doc(doctype, name)
    except frappe.DoesNotExistError:
     pass
    else:
     doc.run_method(u'before_reload')
   else:
    doc = frappe.get_doc(doctype, name)
    update_flags(doc, flags, ignore_permissions)
    check_permission_and_not_submitted(doc)
    frappe.db.sql(u'delete from `tabCustom Field` where dt = %s', name)
    frappe.db.sql(u'delete from `tabCustom Script` where dt = %s', name)
    frappe.db.sql(u'delete from `tabProperty Setter` where doc_type = %s', name)
    frappe.db.sql(u'delete from `tabReport` where ref_doctype=%s', name)
   delete_from_table(doctype, name, ignore_doctypes, None)
  else:
   doc = frappe.get_doc(doctype, name)
   if (not for_reload):
    update_flags(doc, flags, ignore_permissions)
    check_permission_and_not_submitted(doc)
    if (not ignore_on_trash):
     doc.run_method(u'on_trash')
     doc.run_method(u'on_change')
    frappe.enqueue(u'frappe.model.delete_doc.delete_dynamic_links', doctype=doc.doctype, name=doc.name, async=(False if frappe.flags.in_test else True))
    if (not force):
     check_if_doc_is_linked(doc)
     check_if_doc_is_dynamically_linked(doc)
   update_naming_series(doc)
   delete_from_table(doctype, name, ignore_doctypes, doc)
   doc.run_method(u'after_delete')
   remove_all(doctype, name, from_delete=True)
  if (doc and (not for_reload)):
   add_to_deleted_document(doc)
   if (not frappe.flags.in_patch):
    try:
     doc.notify_update()
     insert_feed(doc)
    except ImportError:
     pass
   frappe.defaults.clear_default(parenttype=u'User Permission', key=doctype, value=name)

def delete_doc ( doctype = None , name = None , force = 0 , ignore_doctypes = None , for_reload = False , ignore_permissions = False , flags = None , ignore_on_trash = False ) : if ( not ignore_doctypes ) : ignore_doctypes = [ ] if ( not doctype ) : doctype = frappe . form_dict . get ( u'dt' ) name = frappe . form_dict . get ( u'dn' ) names = name if isinstance ( name , basestring ) : names = [ name ] for name in ( names or [ ] ) : if ( not frappe . db . exists ( doctype , name ) ) : return delete_all_passwords_for ( doctype , name ) doc = None if ( doctype == u'DocType' ) : if for_reload : try : doc = frappe . get_doc ( doctype , name ) except frappe . DoesNotExistError : pass else : doc . run_method ( u'before_reload' ) else : doc = frappe . get_doc ( doctype , name ) update_flags ( doc , flags , ignore_permissions ) check_permission_and_not_submitted ( doc ) frappe . db . sql ( u'delete from `tabCustom Field` where dt = %s' , name ) frappe . db . sql ( u'delete from `tabCustom Script` where dt = %s' , name ) frappe . db . sql ( u'delete from `tabProperty Setter` where doc_type = %s' , name ) frappe . db . sql ( u'delete from `tabReport` where ref_doctype=%s' , name ) delete_from_table ( doctype , name , ignore_doctypes , None ) else : doc = frappe . get_doc ( doctype , name ) if ( not for_reload ) : update_flags ( doc , flags , ignore_permissions ) check_permission_and_not_submitted ( doc ) if ( not ignore_on_trash ) : doc . run_method ( u'on_trash' ) doc . run_method ( u'on_change' ) frappe . enqueue ( u'frappe.model.delete_doc.delete_dynamic_links' , doctype = doc . doctype , name = doc . name , async = ( False if frappe . flags . in_test else True ) ) if ( not force ) : check_if_doc_is_linked ( doc ) check_if_doc_is_dynamically_linked ( doc ) update_naming_series ( doc ) delete_from_table ( doctype , name , ignore_doctypes , doc ) doc . run_method ( u'after_delete' ) remove_all ( doctype , name , from_delete = True ) if ( doc and ( not for_reload ) ) : add_to_deleted_document ( doc ) if ( not frappe . flags . in_patch ) : try : doc . notify_update ( ) insert_feed ( doc ) except ImportError : pass frappe . defaults . clear_default ( parenttype = u'User Permission' , key = doctype , value = name )
delete a document .