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.

45 lines
1.5 KiB

9 years ago
  1. from odoo import api, models, fields
  2. class MailMessage(models.Model):
  3. _inherit = 'mail.message'
  4. sent = fields.Boolean('Sent', compute="_compute_sent", help='Was message sent to someone', store=True)
  5. @api.depends('author_id', 'partner_ids', 'channel_ids')
  6. def _compute_sent(self):
  7. for r in self:
  8. r_sudo = r.sudo()
  9. recipient_ids = r_sudo.partner_ids
  10. author_id = r_sudo.author_id
  11. res_id = r_sudo.model and r_sudo.res_id and r_sudo.env[r_sudo.model].browse(r_sudo.res_id)
  12. sent = author_id and (
  13. len(recipient_ids) > 1
  14. or (
  15. len(recipient_ids) == 1
  16. and recipient_ids[0].id != author_id.id
  17. )
  18. or (
  19. len(r_sudo.channel_ids)
  20. )
  21. or (
  22. res_id
  23. and len(res_id.message_partner_ids - author_id) > 0
  24. )
  25. )
  26. r.sent = sent
  27. def message_format(self):
  28. message_values = super(MailMessage, self).message_format()
  29. message_index = {message['id']: message for message in message_values}
  30. for item in self:
  31. msg = message_index.get(item.id)
  32. if msg:
  33. msg['sent'] = item.sent
  34. return message_values
  35. class MailComposeMessage(models.TransientModel):
  36. _inherit = 'mail.compose.message'
  37. sent = fields.Boolean('Sent', help='dummy field to fix inherit error')