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.

43 lines
1.5 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. import time
  5. from datetime import datetime
  6. from email.utils import COMMASPACE
  7. from openerp import models, api, fields
  8. class MailMail(models.Model):
  9. _inherit = 'mail.mail'
  10. @api.model
  11. def _tracking_email_prepare(self, mail, partner, email):
  12. ts = time.time()
  13. dt = datetime.utcfromtimestamp(ts)
  14. email_to_list = email.get('email_to', [])
  15. email_to = COMMASPACE.join(email_to_list)
  16. return {
  17. 'name': email.get('subject', False),
  18. 'timestamp': '%.6f' % ts,
  19. 'time': fields.Datetime.to_string(dt),
  20. 'mail_id': mail.id if mail else False,
  21. 'mail_message_id': mail.mail_message_id.id if mail else False,
  22. 'partner_id': partner.id if partner else False,
  23. 'recipient': email_to,
  24. 'sender': mail.email_from,
  25. }
  26. @api.model
  27. def send_get_email_dict(self, mail, partner=None):
  28. email = super(MailMail, self).send_get_email_dict(
  29. mail, partner=partner)
  30. m_tracking = self.env['mail.tracking.email']
  31. tracking_email = False
  32. if mail:
  33. vals = self._tracking_email_prepare(mail, partner, email)
  34. tracking_email = m_tracking.sudo().create(vals)
  35. if tracking_email:
  36. email = tracking_email.tracking_img_add(email)
  37. return email