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.

40 lines
1.2 KiB

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