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.

44 lines
1.4 KiB

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