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.

41 lines
1.6 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. from openerp import models, fields, api
  5. class MailTrackingEmail(models.Model):
  6. _inherit = "mail.tracking.email"
  7. mass_mailing_id = fields.Many2one(
  8. string="Mass mailing", comodel_name='mail.mass_mailing', readonly=True)
  9. mail_stats_id = fields.Many2one(
  10. string="Mail statistics", comodel_name='mail.mail.statistics',
  11. readonly=True)
  12. mail_id_int = fields.Integer(string="Mail ID", readonly=True)
  13. @api.model
  14. def _statistics_link_prepare(self, tracking):
  15. return {
  16. 'mail_tracking_id': tracking.id,
  17. }
  18. @api.model
  19. def create(self, vals):
  20. tracking = super(MailTrackingEmail, self).create(vals)
  21. # Link mail statistics with this tracking
  22. if tracking.mail_stats_id:
  23. tracking.mail_stats_id.write(
  24. self._statistics_link_prepare(tracking))
  25. # Get partner from mail statistics
  26. # if mass_mailing_partner addon installed
  27. if ('partner_id' in tracking.mail_stats_id._fields and
  28. tracking.mail_stats_id.partner_id and
  29. not tracking.partner_id):
  30. tracking.partner_id = tracking.mail_stats_id.partner_id.id
  31. # Add this tracking to mass mailing contacts with this recipient
  32. self.tracking_ids_recalculate(
  33. 'mail.mass_mailing.contact', 'email', 'tracking_email_ids',
  34. tracking.recipient_address, new_tracking=tracking)
  35. return tracking