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.

34 lines
1.1 KiB

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