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.

assign_to.py 4.6 KiB

13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. # notify
  56. if not args.get("no_notification"):
  57. notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=args.get('notify'))
  58. # update feeed
  59. try:
  60. import home
  61. from webnotes.utils import get_fullname
  62. home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
  63. '[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
  64. except ImportError, e:
  65. pass
  66. return get(args)
  67. @webnotes.whitelist()
  68. def remove(args=None):
  69. """remove from todo"""
  70. if not args:
  71. args = webnotes.form_dict
  72. res = webnotes.conn.sql("""\
  73. select assigned_by, owner, reference_type, reference_name from `tabToDo`
  74. where reference_type=%(doctype)s and reference_name=%(name)s
  75. and owner=%(assign_to)s""", args)
  76. webnotes.conn.sql("""delete from `tabToDo`
  77. where reference_type=%(doctype)s and reference_name=%(name)s
  78. and owner=%(assign_to)s""", args)
  79. if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3])
  80. return get(args)
  81. def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0):
  82. """
  83. Notify assignee that there is a change in assignment
  84. """
  85. if not (assigned_by and owner and doc_type and doc_name): return
  86. # self assignment / closing - no message
  87. if assigned_by==owner:
  88. return
  89. from webnotes.boot import get_fullnames
  90. user_info = get_fullnames()
  91. # Search for email address in description -- i.e. assignee
  92. assignment = """<a href="#!Form/%s/%s">%s: %s</a>""" % (doc_type, doc_name,
  93. doc_type, doc_name)
  94. if action=='CLOSE':
  95. if owner == webnotes.session.get('user'):
  96. arg = {
  97. 'contact': assigned_by,
  98. 'txt': "The task %s, that you assigned to %s, has been \
  99. closed." % (assignment,
  100. user_info.get(owner, {}).get('fullname'))
  101. }
  102. else:
  103. arg = {
  104. 'contact': assigned_by,
  105. 'txt': "The task %s, that you assigned to %s, \
  106. has been closed by %s." % (assignment,
  107. user_info.get(owner, {}).get('fullname'),
  108. user_info.get(webnotes.session.get('user'),
  109. {}).get('fullname'))
  110. }
  111. else:
  112. arg = {
  113. 'contact': owner,
  114. 'txt': "A new task, %s, has been assigned to you by %s." \
  115. % (assignment,
  116. user_info.get(webnotes.session.get('user'), {}).get('fullname')),
  117. 'notify': notify
  118. }
  119. arg["parenttype"] = "Assignment"
  120. from utilities.page.messages import messages
  121. import json
  122. messages.post(json.dumps(arg))