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.

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