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.

36 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class MailMailStatistics(models.Model):
  6. _inherit = "mail.mail.statistics"
  7. partner_id = fields.Many2one(
  8. string="Partner", comodel_name='res.partner', readonly=True)
  9. @api.model
  10. def partner_id_from_obj(self, model, res_id):
  11. partner_id = False
  12. obj = self.env[model].browse(res_id)
  13. if obj.exists():
  14. if model == 'res.partner':
  15. partner_id = res_id
  16. elif 'partner_id' in obj._fields:
  17. partner_id = obj.partner_id.id
  18. return partner_id
  19. def partner_link(self):
  20. for stat in self.filtered(lambda r: r.model and r.res_id):
  21. partner_id = self.partner_id_from_obj(stat.model, stat.res_id)
  22. if partner_id != stat.partner_id.id:
  23. stat.partner_id = partner_id
  24. return True
  25. @api.model
  26. def create(self, vals):
  27. stat = super(MailMailStatistics, self).create(vals)
  28. stat.partner_link()
  29. return stat