Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

122 lignes
3.7 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. from __future__ import unicode_literals
  23. import webnotes
  24. import webnotes.model.doc
  25. import webnotes.utils
  26. @webnotes.whitelist()
  27. def getdoc():
  28. """
  29. Loads a doclist for a given document. This method is called directly from the client.
  30. Requries "doctype", "name" as form variables.
  31. Will also call the "onload" method on the document.
  32. """
  33. import webnotes
  34. form = webnotes.form_dict
  35. doctype, docname = form.get('doctype'), form.get('name')
  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']))
  41. # load doctype along with the doc
  42. if form.get('getdoctype'):
  43. import webnotes.model.doctype
  44. doclist += webnotes.model.doctype.get(doctype, processed=True)
  45. webnotes.response['docs'] = doclist
  46. @webnotes.whitelist()
  47. def getdoctype():
  48. """load doctype"""
  49. import webnotes.model.doctype
  50. import webnotes.model.meta
  51. doclist = []
  52. dt = webnotes.form_dict.get('doctype')
  53. with_parent = webnotes.form_dict.get('with_parent')
  54. # with parent (called from report builder)
  55. if with_parent:
  56. parent_dt = webnotes.model.meta.get_parent_dt(dt)
  57. if parent_dt:
  58. doclist = webnotes.model.doctype.get(parent_dt, processed=True)
  59. webnotes.response['parent_dt'] = parent_dt
  60. if not doclist:
  61. doclist = webnotes.model.doctype.get(dt, processed=True)
  62. # if single, send the record too
  63. if doclist[0].issingle:
  64. doclist += webnotes.model.doc.get(dt)
  65. # load search criteria for reports (all)
  66. doclist +=get_search_criteria(dt)
  67. webnotes.response['docs'] = doclist
  68. def load_single_doc(dt, dn, user):
  69. """load doc and call onload methods"""
  70. # ----- REPLACE BY webnotes.client.get ------
  71. if not dn: dn = dt
  72. if not webnotes.conn.exists(dt, dn):
  73. return None
  74. try:
  75. dl = webnotes.bean(dt, dn).doclist
  76. except Exception, e:
  77. webnotes.errprint(webnotes.utils.getTraceback())
  78. webnotes.msgprint('Error in script while loading')
  79. raise e
  80. if dl and not dn.startswith('_'):
  81. webnotes.user.update_recent(dt, dn)
  82. # load search criteria ---- if doctype
  83. # ----- TO BE DEPRECATED -----
  84. if dt=='DocType':
  85. dl += get_search_criteria(dt)
  86. return dl
  87. def get_search_criteria(dt):
  88. """bundle search criteria with doctype"""
  89. import webnotes.model.doc
  90. # load search criteria for reports (all)
  91. dl = []
  92. 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))
  93. for sc in sc_list:
  94. if sc[0]:
  95. dl += webnotes.model.doc.get('Search Criteria', sc[0])
  96. return dl