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.

35 lines
1.1 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. from odoo import api, fields, models
  4. class MailMailStatistics(models.Model):
  5. _inherit = "mail.mail.statistics"
  6. partner_id = fields.Many2one(
  7. string="Partner", comodel_name='res.partner', readonly=True)
  8. @api.model
  9. def partner_id_from_obj(self, model, res_id):
  10. partner_id = False
  11. obj = self.env[model].browse(res_id)
  12. if obj.exists():
  13. if model == 'res.partner':
  14. partner_id = res_id
  15. elif 'partner_id' in obj._fields:
  16. partner_id = obj.partner_id.id
  17. return partner_id
  18. def partner_link(self):
  19. for stat in self.filtered(lambda r: r.model and r.res_id):
  20. partner_id = self.partner_id_from_obj(stat.model, stat.res_id)
  21. if partner_id != stat.partner_id.id:
  22. stat.partner_id = partner_id
  23. return True
  24. @api.model
  25. def create(self, vals):
  26. stat = super(MailMailStatistics, self).create(vals)
  27. stat.partner_link()
  28. return stat