Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

152 Zeilen
5.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. from __future__ import unicode_literals
  23. """assign/unassign to ToDo"""
  24. import webnotes
  25. @webnotes.whitelist()
  26. def get(args=None):
  27. """get assigned to"""
  28. if not args:
  29. args = webnotes.form_dict
  30. return webnotes.conn.sql("""select owner from `tabToDo`
  31. where reference_type=%(doctype)s and reference_name=%(name)s
  32. order by modified desc limit 5""", args, as_dict=1)
  33. @webnotes.whitelist()
  34. def add(args=None):
  35. """add in someone's to do list"""
  36. if not args:
  37. args = webnotes.form_dict
  38. if webnotes.conn.sql("""select owner from `tabToDo`
  39. where reference_type=%(doctype)s and reference_name=%(name)s
  40. and owner=%(assign_to)s""", args):
  41. webnotes.msgprint("Already in todo")
  42. return
  43. else:
  44. from webnotes.model.doc import Document
  45. from webnotes.utils import nowdate
  46. d = Document("ToDo")
  47. d.owner = args['assign_to']
  48. d.reference_type = args['doctype']
  49. d.reference_name = args['name']
  50. d.description = args['description']
  51. d.priority = args.get('priority', 'Medium')
  52. d.date = args.get('date', nowdate())
  53. d.assigned_by = args.get('assigned_by', webnotes.user.name)
  54. d.save(1)
  55. # set assigned_to if field exists
  56. from webnotes.model.meta import has_field
  57. if has_field(args['doctype'], "assigned_to"):
  58. webnotes.conn.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to'])
  59. # notify
  60. if not args.get("no_notification"):
  61. notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=args.get('notify'))
  62. # update feeed
  63. try:
  64. import home
  65. from webnotes.utils import get_fullname
  66. home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
  67. '[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
  68. except ImportError, e:
  69. pass
  70. return get(args)
  71. @webnotes.whitelist()
  72. def remove(doctype, name, assign_to):
  73. """remove from todo"""
  74. res = webnotes.conn.sql("""\
  75. select assigned_by, owner, reference_type, reference_name from `tabToDo`
  76. where reference_type=%(doctype)s and reference_name=%(name)s
  77. and owner=%(assign_to)s""", locals())
  78. webnotes.conn.sql("""delete from `tabToDo`
  79. where reference_type=%(doctype)s and reference_name=%(name)s
  80. and owner=%(assign_to)s""", locals())
  81. # clear assigned_to if field exists
  82. from webnotes.model.meta import has_field
  83. if has_field(doctype, "assigned_to"):
  84. webnotes.conn.set_value(doctype, name, "assigned_to", None)
  85. if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3])
  86. return get({"doctype": doctype, "name": name})
  87. def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0):
  88. """
  89. Notify assignee that there is a change in assignment
  90. """
  91. if not (assigned_by and owner and doc_type and doc_name): return
  92. # self assignment / closing - no message
  93. if assigned_by==owner:
  94. return
  95. from webnotes.boot import get_fullnames
  96. user_info = get_fullnames()
  97. # Search for email address in description -- i.e. assignee
  98. from webnotes.utils import get_url_to_form
  99. assignment = get_url_to_form(doc_type, doc_name, label="%s: %s" % (doc_type, doc_name))
  100. if action=='CLOSE':
  101. if owner == webnotes.session.get('user'):
  102. arg = {
  103. 'contact': assigned_by,
  104. 'txt': "The task %s, that you assigned to %s, has been \
  105. closed." % (assignment,
  106. user_info.get(owner, {}).get('fullname'))
  107. }
  108. else:
  109. arg = {
  110. 'contact': assigned_by,
  111. 'txt': "The task %s, that you assigned to %s, \
  112. has been closed by %s." % (assignment,
  113. user_info.get(owner, {}).get('fullname'),
  114. user_info.get(webnotes.session.get('user'),
  115. {}).get('fullname'))
  116. }
  117. else:
  118. arg = {
  119. 'contact': owner,
  120. 'txt': "A new task, %s, has been assigned to you by %s." \
  121. % (assignment,
  122. user_info.get(webnotes.session.get('user'), {}).get('fullname')),
  123. 'notify': notify
  124. }
  125. arg["parenttype"] = "Assignment"
  126. from core.page.messages import messages
  127. import json
  128. messages.post(json.dumps(arg))