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.

34 lines
1.2 KiB

  1. # Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import time
  4. from datetime import datetime
  5. from email.utils import COMMASPACE
  6. from odoo import models, fields
  7. class MailMail(models.Model):
  8. _inherit = 'mail.mail'
  9. def _tracking_email_prepare(self, partner, email):
  10. ts = time.time()
  11. dt = datetime.utcfromtimestamp(ts)
  12. email_to_list = email.get('email_to', [])
  13. email_to = COMMASPACE.join(email_to_list)
  14. return {
  15. 'name': self.subject,
  16. 'timestamp': '%.6f' % ts,
  17. 'time': fields.Datetime.to_string(dt),
  18. 'mail_id': self.id,
  19. 'mail_message_id': self.mail_message_id.id,
  20. 'partner_id': partner.id if partner else False,
  21. 'recipient': email_to,
  22. 'sender': self.email_from,
  23. }
  24. def _send_prepare_values(self, partner=None):
  25. email = super(MailMail, self)._send_prepare_values(partner=partner)
  26. vals = self._tracking_email_prepare(partner, email)
  27. tracking_email = self.env['mail.tracking.email'].sudo().create(vals)
  28. return tracking_email.tracking_img_add(email)