Advertisement
Guest User

Untitled

a guest
Sep 5th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. def delete_doc(doctype=None, name=None, doclist = None, force=0, ignore_doctypes=[], for_reload=False):
  2. """
  3. Deletes a doc(dt, dn) and validates if it is not submitted and not linked in a live record
  4. """
  5. import webnotes.model.meta
  6.  
  7. # get from form
  8. if not doctype:
  9. doctype = webnotes.form_dict.get('dt')
  10. name = webnotes.form_dict.get('dn')
  11.  
  12. if not doctype:
  13. webnotes.msgprint('Nothing to delete!', raise_exception =1)
  14.  
  15. # already deleted..?
  16. if not webnotes.conn.exists(doctype, name):
  17. return
  18.  
  19. if not for_reload:
  20. check_role1=webnotes.conn.sql("select role from `tabUserRole` where parent='"+webnotes.session.user+"'")
  21. res= check_role1 and check_role1[0][0] or ''
  22. if res not in('RMN Manager'):
  23. check_permission_and_not_submitted(doctype, name)
  24. run_on_trash(doctype, name, doclist)
  25. # check if links exist
  26. if not force:
  27. if doctype not in('Customer'):
  28. check_if_doc_is_linked(doctype, name)
  29.  
  30. try:
  31. tablefields = webnotes.model.meta.get_table_fields(doctype)
  32. webnotes.conn.sql("delete from `tab%s` where name=%s" % (doctype, "%s"), name)
  33. if doctype in('Customer'):
  34. msgprint("Deleted Successfully")
  35. webnotes.conn.sql("delete from `tabRenew Subscription` where customer='"+name+"'")
  36. webnotes.conn.sql("delete from `tabSubscription Renew` where customer='"+name+"'")
  37. webnotes.conn.sql("delete from `tabSales Order` where customer='"+name+"'")
  38. webnotes.conn.sql("delete from `tabDelivery Note` where customer='"+name+"'")
  39. webnotes.conn.sql("delete from `tabSales Invoice` where customer='"+name+"'")
  40. for t in tablefields:
  41. if t[0] not in ignore_doctypes:
  42. webnotes.conn.sql("delete from `tab%s` where parent = %s" % (t[0], '%s'), name)
  43. except Exception, e:
  44. if e.args[0]==1451:
  45. webnotes.msgprint("Cannot delete %s '%s' as it is referenced in another record. You must delete the referred record first" % (doctype, name))
  46.  
  47. raise e
  48.  
  49. return 'okay'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement