You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 line
4.0 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. import webnotes
  23. import webnotes.model.doc
  24. @webnotes.whitelist()
  25. def getdoc():
  26. """
  27. Loads a doclist for a given document. This method is called directly from the client.
  28. Requries "doctype", "name" as form variables.
  29. Will also call the "onload" method on the document.
  30. """
  31. import webnotes
  32. from webnotes.utils import cint
  33. form = webnotes.form_dict
  34. doctype, docname = form.get('doctype'), form.get('name')
  35. prefix = cint(form.get('from_archive')) and 'arc' or 'tab'
  36. if not (doctype and docname):
  37. raise Exception, 'doctype and name required!'
  38. doclist = []
  39. # single
  40. doclist = load_single_doc(doctype, docname, (form.get('user') or webnotes.session['user']), prefix)
  41. # load doctype along with the doc
  42. if form.get('getdoctype'):
  43. import webnotes.model.doctype
  44. doclist += webnotes.model.doctype.get(doctype)
  45. # tag as archived
  46. if prefix == 'arc':
  47. doclist[0].__archived=1
  48. webnotes.response['docs'] = doclist
  49. @webnotes.whitelist()
  50. def getdoctype():
  51. """load doctype"""
  52. import webnotes.model.doctype
  53. import webnotes.model.meta
  54. form, doclist = webnotes.form, []
  55. dt = form.getvalue('doctype')
  56. with_parent = form.getvalue('with_parent')
  57. # with parent (called from report builder)
  58. if with_parent:
  59. parent_dt = webnotes.model.meta.get_parent_dt(dt)
  60. if parent_dt:
  61. doclist = webnotes.model.doctype.get(parent_dt)
  62. webnotes.response['parent_dt'] = parent_dt
  63. if not doclist:
  64. doclist = webnotes.model.doctype.get(dt)
  65. # if single, send the record too
  66. if doclist[0].issingle:
  67. doclist += webnotes.model.doc.get(dt)
  68. # load search criteria for reports (all)
  69. doclist +=get_search_criteria(dt)
  70. webnotes.response['docs'] = doclist
  71. def load_single_doc(dt, dn, user, prefix):
  72. """load doc and call onload methods"""
  73. import webnotes.model.code
  74. if not dn: dn = dt
  75. dl = webnotes.model.doc.get(dt, dn, prefix=prefix)
  76. # archive, done
  77. if prefix=='arc':
  78. return dl
  79. try:
  80. so, r = webnotes.model.code.get_server_obj(dl[0], dl), None
  81. if hasattr(so, 'onload'):
  82. r = webnotes.model.code.run_server_obj(so, 'onload')
  83. if hasattr(so, 'custom_onload'):
  84. r = webnotes.model.code.run_server_obj(so, 'custom_onload')
  85. if r:
  86. webnotes.msgprint(r)
  87. except Exception, e:
  88. webnotes.errprint(webnotes.utils.getTraceback())
  89. webnotes.msgprint('Error in script while loading')
  90. raise e
  91. if dl and not dn.startswith('_'):
  92. webnotes.user.update_recent(dt, dn)
  93. # load search criteria ---- if doctype
  94. if dt=='DocType':
  95. dl += get_search_criteria(dt)
  96. return dl
  97. def get_search_criteria(dt):
  98. """bundle search criteria with doctype"""
  99. import webnotes.model.doc
  100. # load search criteria for reports (all)
  101. dl = []
  102. sc_list = webnotes.conn.sql("select name from `tabSearch Criteria` where doc_type = '%s' or parent_doc_type = '%s' and (disabled!=1 OR disabled IS NULL)" % (dt, dt))
  103. for sc in sc_list:
  104. if sc[0]:
  105. dl += webnotes.model.doc.get('Search Criteria', sc[0])
  106. return dl