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.

43 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. def message_format(self):
  26. message_values = super(MailMessage, self).message_format()
  27. message_index = {message["id"]: message for message in message_values}
  28. for item in self:
  29. msg = message_index.get(item.id)
  30. if msg:
  31. msg["sent"] = item.sent
  32. return message_values
  33. class MailComposeMessage(models.TransientModel):
  34. _inherit = "mail.compose.message"
  35. sent = fields.Boolean("Sent", help="dummy field to fix inherit error")