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.1 KiB

13 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. """assign/unassign to ToDo"""
  23. import webnotes
  24. @webnotes.whitelist()
  25. def get():
  26. """get assigned to"""
  27. return webnotes.conn.sql("""select owner from `tabToDo Item`
  28. where reference_type=%(doctype)s and reference_name=%(name)s
  29. order by modified desc limit 5""", webnotes.form_dict, as_dict=1)
  30. @webnotes.whitelist()
  31. def add():
  32. """add in someone's to do list"""
  33. if webnotes.conn.sql("""select owner from `tabToDo Item`
  34. where reference_type=%(doctype)s and reference_name=%(name)s
  35. and owner=%(assign_to)s""", webnotes.form_dict):
  36. webnotes.msgprint("Already in todo")
  37. return
  38. else:
  39. from webnotes.model.doc import Document
  40. from webnotes.utils import nowdate
  41. d = Document("ToDo Item")
  42. d.owner = webnotes.form_dict['assign_to']
  43. d.reference_type = webnotes.form_dict['doctype']
  44. d.reference_name = webnotes.form_dict['name']
  45. d.description = webnotes.form_dict['description']
  46. d.priority = webnotes.form_dict.get('priority', 'Medium')
  47. d.date = webnotes.form_dict.get('date', nowdate())
  48. d.assigned_by = webnotes.user.name
  49. d.save(1)
  50. # notify
  51. notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=webnotes.form_dict.get('notify'))
  52. # update feeed
  53. try:
  54. import home
  55. from webnotes.utils import get_fullname
  56. home.make_feed('Assignment', d.reference_type, d.reference_name, webnotes.session['user'],
  57. '[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)), '#C78F58')
  58. except ImportError, e:
  59. pass
  60. return get()
  61. @webnotes.whitelist()
  62. def remove():
  63. """remove from todo"""
  64. res = webnotes.conn.sql("""\
  65. select assigned_by, owner, reference_type, reference_name from `tabToDo Item`
  66. where reference_type=%(doctype)s and reference_name=%(name)s
  67. and owner=%(assign_to)s""", webnotes.form_dict)
  68. webnotes.conn.sql("""delete from `tabToDo Item`
  69. where reference_type=%(doctype)s and reference_name=%(name)s
  70. and owner=%(assign_to)s""", webnotes.form_dict)
  71. if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3])
  72. return get()
  73. def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0):
  74. """
  75. Notify assignee that there is a change in assignment
  76. """
  77. if not (assigned_by and owner and doc_type and doc_name): return
  78. # Search for email address in description -- i.e. assignee
  79. assignment = """<a href="#!Form/%s/%s">%s</a>""" % (doc_type, doc_name, doc_name)
  80. if action=='CLOSE':
  81. if owner == webnotes.session.get('user'):
  82. arg = {
  83. 'uid': assigned_by,
  84. 'comment': "The task %s, that you assigned to %s, has been \
  85. closed." % (assignment, owner)
  86. }
  87. else:
  88. arg = {
  89. 'uid': assigned_by,
  90. 'comment': "The task %s, that you assigned to %s, \
  91. has been closed by %s." % (assignment, owner,
  92. webnotes.session.get('user'))
  93. }
  94. else:
  95. arg = {
  96. 'uid': owner,
  97. 'comment': "A new task, %s, has been assigned to you by %s." \
  98. % (assignment, webnotes.session.get('user')),
  99. 'notify': notify
  100. }
  101. from home.page.my_company import my_company
  102. my_company.post_comment(arg)