No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

112 líneas
2.9 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes, json
  5. import webnotes.model.doc
  6. import webnotes.utils
  7. @webnotes.whitelist()
  8. def getdoc(doctype, name, user=None):
  9. """
  10. Loads a doclist for a given document. This method is called directly from the client.
  11. Requries "doctype", "name" as form variables.
  12. Will also call the "onload" method on the document.
  13. """
  14. import webnotes
  15. if not (doctype and name):
  16. raise Exception, 'doctype and name required!'
  17. if not name:
  18. name = doctype
  19. if not webnotes.conn.exists(doctype, name):
  20. return []
  21. try:
  22. bean = webnotes.bean(doctype, name)
  23. bean.run_method("onload")
  24. doclist = bean.doclist
  25. # add file list
  26. set_docinfo(doctype, name)
  27. except Exception, e:
  28. webnotes.errprint(webnotes.utils.getTraceback())
  29. webnotes.msgprint('Did not load.')
  30. raise
  31. if bean and not name.startswith('_'):
  32. webnotes.user.update_recent(doctype, name)
  33. webnotes.response['docs'] = doclist
  34. @webnotes.whitelist()
  35. def getdoctype(doctype, with_parent=False, cached_timestamp=None):
  36. """load doctype"""
  37. import webnotes.model.doctype
  38. import webnotes.model.meta
  39. doclist = []
  40. # with parent (called from report builder)
  41. if with_parent:
  42. parent_dt = webnotes.model.meta.get_parent_dt(doctype)
  43. if parent_dt:
  44. doclist = webnotes.model.doctype.get(parent_dt, processed=True)
  45. webnotes.response['parent_dt'] = parent_dt
  46. if not doclist:
  47. doclist = webnotes.model.doctype.get(doctype, processed=True)
  48. if cached_timestamp and doclist[0].modified==cached_timestamp:
  49. return "use_cache"
  50. webnotes.response['docs'] = doclist
  51. def set_docinfo(doctype, name):
  52. webnotes.response["docinfo"] = {
  53. "attachments": add_attachments(doctype, name),
  54. "comments": add_comments(doctype, name),
  55. "assignments": add_assignments(doctype, name)
  56. }
  57. def add_attachments(dt, dn):
  58. attachments = {}
  59. for f in webnotes.conn.sql("""select name, file_name, file_url from
  60. `tabFile Data` where attached_to_name=%s and attached_to_doctype=%s""",
  61. (dn, dt), as_dict=True):
  62. attachments[f.file_url or f.file_name] = f.name
  63. return attachments
  64. def add_comments(dt, dn, limit=20):
  65. cl = webnotes.conn.sql("""select name, comment, comment_by, creation from `tabComment`
  66. where comment_doctype=%s and comment_docname=%s
  67. order by creation desc limit %s""" % ('%s','%s', limit), (dt, dn), as_dict=1)
  68. return cl
  69. def add_assignments(dt, dn):
  70. cl = webnotes.conn.sql_list("""select owner from `tabToDo`
  71. where reference_type=%(doctype)s and reference_name=%(name)s
  72. order by modified desc limit 5""", {
  73. "doctype": dt,
  74. "name": dn
  75. })
  76. return cl
  77. @webnotes.whitelist()
  78. def get_badge_info(doctypes, filters):
  79. filters = json.loads(filters)
  80. doctypes = json.loads(doctypes)
  81. filters["docstatus"] = ["!=", 2]
  82. out = {}
  83. for doctype in doctypes:
  84. out[doctype] = webnotes.conn.get_value(doctype, filters, "count(*)")
  85. return out