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.

91 lines
3.5 KiB

  1. from openerp import api, models, fields, SUPERUSER_ID
  2. from openerp.tools.translate import _
  3. class wizard(models.TransientModel):
  4. _name = 'mail_move_message.wizard'
  5. message_id = fields.Many2one('mail.message', string='Message')
  6. message_body = fields.Html(related='message_id.body', string='Message to move', readonly=True)
  7. parent_id = fields.Many2one('mail.message', string='Search by name')
  8. model_id = fields.Many2one('ir.model', string='Record type')
  9. res_id = fields.Integer('Record ID')
  10. record_url = fields.Char('Link to record', readonly=True)
  11. @api.onchange('parent_id')
  12. def on_change_parent_id(self):
  13. if self.parent_id and self.parent_id.model:
  14. self.model_id = self.env['ir.model'].search([('model', '=', self.parent_id.model)])[0]
  15. self.res_id = self.parent_id.res_id
  16. else:
  17. self.model_id = None
  18. self.res_id = None
  19. @api.onchange('model_id', 'res_id')
  20. def on_change_res(self):
  21. if not ( self.model_id and self.res_id ):
  22. self.record_url = ''
  23. return
  24. self.record_url = '/web#id=%s&model=%s' % (self.res_id, self.model_id.model)
  25. @api.one
  26. def check_access(self):
  27. cr = self._cr
  28. uid = self.env.user.id
  29. operation = 'write'
  30. context = self._context
  31. if not ( self.model_id and self.res_id ):
  32. return True
  33. model_obj = self.pool[self.model_id.model]
  34. mids = model_obj.exists(cr, uid, [self.res_id])
  35. if hasattr(model_obj, 'check_mail_message_access'):
  36. model_obj.check_mail_message_access(cr, uid, mids, operation, context=context)
  37. else:
  38. self.pool['mail.thread'].check_mail_message_access(cr, uid, mids, operation, model_obj=model_obj, context=context)
  39. @api.multi
  40. def move(self):
  41. for r in self:
  42. r.check_access()
  43. if r.parent_id:
  44. if not (r.parent_id.model == r.model_id.model and
  45. r.parent_id.res_id == r.res_id):
  46. r.parent_id = None
  47. r.message_id.sudo().write({'parent_id': r.parent_id.id, 'res_id': r.res_id, 'model': r.model_id.model})
  48. if not ( r.model_id and r.res_id ):
  49. obj = self.pool.get('ir.model.data').get_object_reference(self._cr, SUPERUSER_ID, 'mail', 'mail_archivesfeeds')[1]
  50. return {
  51. 'type' : 'ir.actions.client',
  52. 'name' : 'Archive',
  53. 'tag' : 'reload',
  54. 'params' : {'menu_id': obj},
  55. }
  56. return {
  57. 'name': _('Record'),
  58. 'view_type': 'form',
  59. 'view_mode': 'form',
  60. 'res_model': r.model_id.model,
  61. 'res_id': r.res_id,
  62. 'views': [(False, 'form')],
  63. 'type': 'ir.actions.act_window',
  64. }
  65. class mail_message(models.Model):
  66. _inherit = 'mail.message'
  67. def name_get(self, cr, uid, ids, context=None):
  68. if not (context or {}).get('extended_name'):
  69. return super(mail_message, self).name_get(cr, uid, ids, context=context)
  70. if isinstance(ids, (list, tuple)) and not len(ids):
  71. return []
  72. if isinstance(ids, (long, int)):
  73. ids = [ids]
  74. reads = self.read(cr, uid, ids, ['record_name','model', 'res_id'], context=context)
  75. res = []
  76. for record in reads:
  77. name = record['record_name']
  78. extended_name = ' [%s] ID %s' % (record.get('model', 'UNDEF'), record.get('res_id', 'UNDEF'))
  79. res.append((record['id'], name + extended_name))
  80. return res