Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def delete_doc(doctype=None, name=None, doclist = None, force=0, ignore_doctypes=[], for_reload=False):
- """
- Deletes a doc(dt, dn) and validates if it is not submitted and not linked in a live record
- """
- import webnotes.model.meta
- # get from form
- if not doctype:
- doctype = webnotes.form_dict.get('dt')
- name = webnotes.form_dict.get('dn')
- if not doctype:
- webnotes.msgprint('Nothing to delete!', raise_exception =1)
- # already deleted..?
- if not webnotes.conn.exists(doctype, name):
- return
- if not for_reload:
- check_role1=webnotes.conn.sql("select role from `tabUserRole` where parent='"+webnotes.session.user+"'")
- res= check_role1 and check_role1[0][0] or ''
- if res not in('RMN Manager'):
- check_permission_and_not_submitted(doctype, name)
- run_on_trash(doctype, name, doclist)
- # check if links exist
- if not force:
- if doctype not in('Customer'):
- check_if_doc_is_linked(doctype, name)
- try:
- tablefields = webnotes.model.meta.get_table_fields(doctype)
- webnotes.conn.sql("delete from `tab%s` where name=%s" % (doctype, "%s"), name)
- if doctype in('Customer'):
- msgprint("Deleted Successfully")
- webnotes.conn.sql("delete from `tabRenew Subscription` where customer='"+name+"'")
- webnotes.conn.sql("delete from `tabSubscription Renew` where customer='"+name+"'")
- webnotes.conn.sql("delete from `tabSales Order` where customer='"+name+"'")
- webnotes.conn.sql("delete from `tabDelivery Note` where customer='"+name+"'")
- webnotes.conn.sql("delete from `tabSales Invoice` where customer='"+name+"'")
- for t in tablefields:
- if t[0] not in ignore_doctypes:
- webnotes.conn.sql("delete from `tab%s` where parent = %s" % (t[0], '%s'), name)
- except Exception, e:
- if e.args[0]==1451:
- webnotes.msgprint("Cannot delete %s '%s' as it is referenced in another record. You must delete the referred record first" % (doctype, name))
- raise e
- return 'okay'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement