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.

54 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. class MailMessage(models.Model):
  8. _inherit = "mail.message"
  9. def _tracking_status_map_get(self):
  10. return {
  11. 'False': 'waiting',
  12. 'error': 'error',
  13. 'deferred': 'sent',
  14. 'sent': 'sent',
  15. 'delivered': 'delivered',
  16. 'opened': 'opened',
  17. 'rejected': 'error',
  18. 'spam': 'error',
  19. 'unsub': 'opened',
  20. 'bounced': 'error',
  21. 'soft-bounced': 'error',
  22. }
  23. def _partner_tracking_status_get(self, tracking_email):
  24. tracking_status_map = self._tracking_status_map_get()
  25. status = 'unknown'
  26. if tracking_email:
  27. tracking_email_status = str(tracking_email.state)
  28. status = tracking_status_map.get(tracking_email_status, 'unknown')
  29. return status
  30. @api.model
  31. def _message_read_dict_postprocess(self, messages, message_tree):
  32. res = super(MailMessage, self)._message_read_dict_postprocess(
  33. messages, message_tree)
  34. for message_dict in messages:
  35. mail_message_id = message_dict.get('id', False)
  36. if mail_message_id:
  37. partner_trackings = {}
  38. for partner in message_dict.get('partner_ids', []):
  39. partner_id = partner[0]
  40. tracking_email = self.env['mail.tracking.email'].search([
  41. ('mail_message_id', '=', mail_message_id),
  42. ('partner_id', '=', partner_id),
  43. ])
  44. status = self._partner_tracking_status_get(tracking_email)
  45. partner_trackings[str(partner_id)] = (
  46. status, tracking_email.id)
  47. message_dict['partner_trackings'] = partner_trackings
  48. return res