2017-06-14 20:47:41 +02:00
|
|
|
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
2020-02-10 11:40:11 +01:00
|
|
|
# Copyright 2020 Tecnativa - Manuel Calero
|
2016-08-08 13:14:37 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
2017-06-14 20:47:41 +02:00
|
|
|
from odoo import api, fields, models
|
2016-08-08 13:14:37 +02:00
|
|
|
|
|
|
|
|
2020-02-10 11:40:11 +01:00
|
|
|
class MailingTrace(models.Model):
|
|
|
|
_inherit = "mailing.trace"
|
2016-08-08 13:14:37 +02:00
|
|
|
|
|
|
|
partner_id = fields.Many2one(
|
2020-02-10 11:35:23 +01:00
|
|
|
string="Partner", comodel_name="res.partner", readonly=True
|
|
|
|
)
|
2016-08-08 13:14:37 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def partner_id_from_obj(self, model, res_id):
|
|
|
|
partner_id = False
|
|
|
|
obj = self.env[model].browse(res_id)
|
|
|
|
if obj.exists():
|
2020-02-10 11:35:23 +01:00
|
|
|
if model == "res.partner":
|
2016-08-08 13:14:37 +02:00
|
|
|
partner_id = res_id
|
2020-02-10 11:35:23 +01:00
|
|
|
elif "partner_id" in obj._fields:
|
2016-08-08 13:14:37 +02:00
|
|
|
partner_id = obj.partner_id.id
|
|
|
|
return partner_id
|
|
|
|
|
|
|
|
def partner_link(self):
|
|
|
|
for stat in self.filtered(lambda r: r.model and r.res_id):
|
|
|
|
partner_id = self.partner_id_from_obj(stat.model, stat.res_id)
|
|
|
|
if partner_id != stat.partner_id.id:
|
|
|
|
stat.partner_id = partner_id
|
|
|
|
return True
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def create(self, vals):
|
2020-02-10 11:40:11 +01:00
|
|
|
stat = super(MailingTrace, self).create(vals)
|
2016-08-08 13:14:37 +02:00
|
|
|
stat.partner_link()
|
|
|
|
return stat
|