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. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, models, fields
  4. class MailActivity(models.Model):
  5. _inherit = 'mail.activity'
  6. partner_id = fields.Many2one(
  7. comodel_name='res.partner',
  8. index=True,
  9. compute='_compute_res_partner_id',
  10. store=True,
  11. )
  12. commercial_partner_id = fields.Many2one(
  13. related='partner_id.commercial_partner_id',
  14. string='Commercial Entity',
  15. store=True,
  16. related_sudo=True,
  17. readonly=True)
  18. @api.depends('res_model', 'res_id')
  19. def _compute_res_partner_id(self):
  20. for obj in self:
  21. res_model = obj.res_model
  22. res_id = obj.res_id
  23. if res_model == 'res.partner':
  24. obj.partner_id = res_id
  25. else:
  26. res_model_id = obj.env[res_model].search([('id', '=', res_id)])
  27. if 'partner_id' in res_model_id._fields and \
  28. res_model_id.partner_id:
  29. obj.partner_id = res_model_id.partner_id
  30. else:
  31. obj.partner_id = None