2016-06-14 17:22:17 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
import time
|
|
|
|
from datetime import datetime
|
|
|
|
from email.utils import COMMASPACE
|
|
|
|
|
2016-10-14 21:53:04 +02:00
|
|
|
from odoo import models, fields
|
2016-06-14 17:22:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MailMail(models.Model):
|
|
|
|
_inherit = 'mail.mail'
|
|
|
|
|
2016-09-09 18:33:21 +02:00
|
|
|
def _tracking_email_prepare(self, partner, email):
|
2016-06-14 17:22:17 +02:00
|
|
|
ts = time.time()
|
|
|
|
dt = datetime.utcfromtimestamp(ts)
|
|
|
|
email_to_list = email.get('email_to', [])
|
|
|
|
email_to = COMMASPACE.join(email_to_list)
|
|
|
|
return {
|
2016-10-14 21:53:04 +02:00
|
|
|
'name': self.subject,
|
2016-06-14 17:22:17 +02:00
|
|
|
'timestamp': '%.6f' % ts,
|
|
|
|
'time': fields.Datetime.to_string(dt),
|
2016-09-09 18:33:21 +02:00
|
|
|
'mail_id': self.id,
|
|
|
|
'mail_message_id': self.mail_message_id.id,
|
2016-06-14 17:22:17 +02:00
|
|
|
'partner_id': partner.id if partner else False,
|
|
|
|
'recipient': email_to,
|
2016-09-09 18:33:21 +02:00
|
|
|
'sender': self.email_from,
|
2016-06-14 17:22:17 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 18:33:21 +02:00
|
|
|
def send_get_email_dict(self, partner=None):
|
|
|
|
email = super(MailMail, self).send_get_email_dict(partner=partner)
|
|
|
|
vals = self._tracking_email_prepare(partner, email)
|
|
|
|
tracking_email = self.env['mail.tracking.email'].sudo().create(vals)
|
|
|
|
return tracking_email.tracking_img_add(email)
|