2018-03-19 16:41:26 +01:00
|
|
|
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
2016-06-14 17:22:17 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
import time
|
|
|
|
from datetime import datetime
|
|
|
|
from email.utils import COMMASPACE
|
2019-07-03 11:12:11 +02:00
|
|
|
|
2019-11-18 11:46:59 +01:00
|
|
|
from odoo import fields, models
|
2016-06-14 17:22:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MailMail(models.Model):
|
2019-11-18 11:46:59 +01:00
|
|
|
_inherit = "mail.mail"
|
2016-06-14 17:22:17 +02:00
|
|
|
|
2016-09-09 18:33:21 +02:00
|
|
|
def _tracking_email_prepare(self, partner, email):
|
2019-10-17 03:28:42 +02:00
|
|
|
"""Prepare email.tracking.email record values"""
|
2016-06-14 17:22:17 +02:00
|
|
|
ts = time.time()
|
|
|
|
dt = datetime.utcfromtimestamp(ts)
|
2019-11-18 11:46:59 +01:00
|
|
|
email_to_list = email.get("email_to", [])
|
2016-06-14 17:22:17 +02:00
|
|
|
email_to = COMMASPACE.join(email_to_list)
|
|
|
|
return {
|
2019-11-18 11:46:59 +01:00
|
|
|
"name": self.subject,
|
|
|
|
"timestamp": "%.6f" % ts,
|
|
|
|
"time": fields.Datetime.to_string(dt),
|
|
|
|
"mail_id": self.id,
|
|
|
|
"mail_message_id": self.mail_message_id.id,
|
|
|
|
"partner_id": partner.id if partner else False,
|
|
|
|
"recipient": email_to,
|
|
|
|
"sender": self.email_from,
|
2016-06-14 17:22:17 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 17:26:01 +01:00
|
|
|
def _send_prepare_values(self, partner=None):
|
2019-10-17 03:28:42 +02:00
|
|
|
"""Creates the mail.tracking.email record and adds the image tracking
|
|
|
|
to the email"""
|
|
|
|
email = super()._send_prepare_values(partner=partner)
|
2016-09-09 18:33:21 +02:00
|
|
|
vals = self._tracking_email_prepare(partner, email)
|
2019-11-18 11:46:59 +01:00
|
|
|
tracking_email = self.env["mail.tracking.email"].sudo().create(vals)
|
2016-09-09 18:33:21 +02:00
|
|
|
return tracking_email.tracking_img_add(email)
|