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.

37 lines
1.2 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 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. @api.multi
  20. def partner_link(self):
  21. for stat in self.filtered(lambda r: r.model and r.res_id):
  22. partner_id = self.partner_id_from_obj(stat.model, stat.res_id)
  23. if partner_id != stat.partner_id.id:
  24. stat.partner_id = partner_id
  25. return True
  26. @api.model
  27. def create(self, vals):
  28. stat = super(MailMailStatistics, self).create(vals)
  29. stat.partner_link()
  30. return stat