Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

71 linhas
2.8 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. # Event
  23. # -------------
  24. import webnotes
  25. @webnotes.whitelist()
  26. def get_cal_events(m_st, m_end):
  27. import webnotes.model.doc
  28. sql = webnotes.conn.sql
  29. # load owned events
  30. res1 = sql("select name from `tabEvent` WHERE ifnull(event_date,'2000-01-01') between '%s' and '%s' and owner = '%s' and event_type != 'Public' and event_type != 'Cancel'" % (m_st, m_end, webnotes.user.name))
  31. # load individual events
  32. res2 = sql("select t1.name from `tabEvent` t1, `tabEvent User` t2 where ifnull(t1.event_date,'2000-01-01') between '%s' and '%s' and t2.person = '%s' and t1.name = t2.parent and t1.event_type != 'Cancel'" % (m_st, m_end, webnotes.user.name))
  33. # load role events
  34. roles = webnotes.user.get_roles()
  35. myroles = ['t2.role = "%s"' % r for r in roles]
  36. myroles = '(' + (' OR '.join(myroles)) + ')'
  37. res3 = sql("select t1.name from `tabEvent` t1, `tabEvent Role` t2 where ifnull(t1.event_date,'2000-01-01') between '%s' and '%s' and t1.name = t2.parent and t1.event_type != 'Cancel' and %s" % (m_st, m_end, myroles))
  38. # load public events
  39. res4 = sql("select name from `tabEvent` where ifnull(event_date,'2000-01-01') between '%s' and '%s' and event_type='Public'" % (m_st, m_end))
  40. doclist, rl = [], []
  41. for r in res1 + res2 + res3 + res4:
  42. if not r in rl:
  43. doclist += webnotes.model.doc.get('Event', r[0])
  44. rl.append(r)
  45. return doclist
  46. # Load Month Events
  47. # -----------------
  48. @webnotes.whitelist()
  49. def load_month_events():
  50. from webnotes.utils import cint
  51. form = webnotes.form
  52. mm = form.getvalue('month')
  53. yy = form.getvalue('year')
  54. m_st = str(yy) + '-%.2i' % cint(mm) + '-01'
  55. m_end = str(yy) + '-%.2i' % cint(mm) + '-31'
  56. webnotes.response['docs'] = get_cal_events(m_st, m_end)