res_users.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import datetime
  4. from odoo import api, fields, models, modules, _
  5. from pytz import timezone, UTC
  6. class Users(models.Model):
  7. _inherit = 'res.users'
  8. def _systray_get_calendar_event_domain(self):
  9. tz = self.env.user.tz
  10. start_dt = datetime.datetime.utcnow()
  11. if tz:
  12. start_date = timezone(tz).localize(start_dt).astimezone(UTC).date()
  13. else:
  14. start_date = datetime.date.today()
  15. end_dt = datetime.datetime.combine(start_date, datetime.time.max)
  16. if tz:
  17. end_dt = timezone(tz).localize(end_dt).astimezone(UTC)
  18. return ['&', '|',
  19. '&',
  20. '|',
  21. ['start', '>=', fields.Datetime.to_string(start_dt)],
  22. ['stop', '>=', fields.Datetime.to_string(start_dt)],
  23. ['start', '<=', fields.Datetime.to_string(end_dt)],
  24. '&',
  25. ['allday', '=', True],
  26. ['start_date', '=', fields.Date.to_string(start_date)],
  27. ('attendee_ids.partner_id', '=', self.env.user.partner_id.id)]
  28. @api.model
  29. def systray_get_activities(self):
  30. res = super(Users, self).systray_get_activities()
  31. meetings_lines = self.env['calendar.event'].search_read(
  32. self._systray_get_calendar_event_domain(),
  33. ['id', 'start', 'name', 'allday', 'attendee_status'],
  34. order='start')
  35. meetings_lines = [line for line in meetings_lines if line['attendee_status'] != 'declined']
  36. if meetings_lines:
  37. meeting_label = _("Today's Meetings")
  38. meetings_systray = {
  39. 'id': self.env['ir.model']._get('calendar.event').id,
  40. 'type': 'meeting',
  41. 'name': meeting_label,
  42. 'model': 'calendar.event',
  43. 'icon': modules.module.get_module_icon(self.env['calendar.event']._original_module),
  44. 'meetings': meetings_lines,
  45. }
  46. res.insert(0, meetings_systray)
  47. return res