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.

39 lines
1.2 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")
  8. def _compute_sent(self):
  9. for r in self:
  10. r_sudo = r.sudo()
  11. sent = (
  12. len(r_sudo.partner_ids) > 1
  13. or len(r_sudo.partner_ids) == 1
  14. and r_sudo.author_id
  15. and r_sudo.partner_ids[0].id != r_sudo.author_id.id
  16. or r_sudo.model == "mail.channel"
  17. and r_sudo.res_id
  18. )
  19. r.sent = sent
  20. @api.multi
  21. def message_format(self):
  22. message_values = super(MailMessage, self).message_format()
  23. message_index = {message["id"]: message for message in message_values}
  24. for item in self:
  25. msg = message_index.get(item.id)
  26. if msg:
  27. msg["sent"] = item.sent
  28. return message_values
  29. class MailComposeMessage(models.TransientModel):
  30. _inherit = "mail.compose.message"
  31. sent = fields.Boolean("Sent", help="dummy field to fix inherit error")