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.

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