def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reload=False,
	ignore_permissions=False, flags=None, ignore_on_trash=False):
	"""
		Deletes a doc(dt, dn) and validates if it is not submitted and not linked in a live record
	"""
	if not ignore_doctypes: ignore_doctypes = []

	# get from form
	if not doctype:
		doctype = frappe.form_dict.get('dt')
		name = frappe.form_dict.get('dn')

	names = name
	if isinstance(name, basestring):
		names = [name]

	for name in names or []:

		# already deleted..?
		if not frappe.db.exists(doctype, name):
			return

		# delete attachments
		remove_all(doctype, name)

		doc = None
		if doctype=="DocType":
			if for_reload:

				try:
					doc = frappe.get_doc(doctype, name)
				except frappe.DoesNotExistError:
					pass
				else:
					doc.run_method("before_reload")

			else:
				frappe.db.sql("delete from `tabCustom Field` where dt = %s", name)
				frappe.db.sql("delete from `tabCustom Script` where dt = %s", name)
				frappe.db.sql("delete from `tabProperty Setter` where doc_type = %s", name)
				frappe.db.sql("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:
				if ignore_permissions:
					if not flags: flags = {}
					flags["ignore_permissions"] = ignore_permissions

				if flags:
					doc.flags.update(flags)

				check_permission_and_not_submitted(doc)

				if not ignore_on_trash:
					doc.run_method("on_trash")
					doc.run_method('on_change')

				dynamic_linked_doctypes = [df.parent for df in get_dynamic_link_map().get(doc.doctype, [])]
				if "ToDo" in dynamic_linked_doctypes:
					delete_linked_todos(doc)

				if "Communication" in dynamic_linked_doctypes:
					delete_linked_communications(doc)

				if "DocShare" in dynamic_linked_doctypes:
					delete_shared(doc)

				if "Email Unsubscribe" in dynamic_linked_doctypes:
					delete_email_subscribe(doc)

				# check if links exist
				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("after_delete")

		if doc:
			try:
				doc.notify_update()
				insert_feed(doc)
			except ImportError:
				pass

		# delete user_permissions
		frappe.defaults.clear_default(parenttype="User Permission", key=doctype, value=name)
dataset/ETHPy150Open frappe/frappe/frappe/model/delete_doc.py/delete_doc/original