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.

74 lines
2.9 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.multi
  26. def move(self):
  27. for r in self:
  28. if r.parent_id:
  29. if not (r.parent_id.model == r.model_id.model and
  30. r.parent_id.res_id == r.res_id):
  31. r.parent_id = None
  32. r.message_id.write({'parent_id': r.parent_id.id, 'res_id': r.res_id, 'model': r.model_id.model})
  33. if not ( r.model_id and r.res_id ):
  34. obj = self.pool.get('ir.model.data').get_object_reference(self._cr, SUPERUSER_ID, 'mail', 'mail_archivesfeeds')[1]
  35. return {
  36. 'type' : 'ir.actions.client',
  37. 'name' : 'Archive',
  38. 'tag' : 'reload',
  39. 'params' : {'menu_id': obj},
  40. }
  41. return {
  42. 'name': _('Record'),
  43. 'view_type': 'form',
  44. 'view_mode': 'form',
  45. 'res_model': r.model_id.model,
  46. 'res_id': r.res_id,
  47. 'views': [(False, 'form')],
  48. 'type': 'ir.actions.act_window',
  49. }
  50. class mail_message(models.Model):
  51. _inherit = 'mail.message'
  52. def name_get(self, cr, uid, ids, context=None):
  53. if not (context or {}).get('extended_name'):
  54. return super(mail_message, self).name_get(cr, uid, ids, context=context)
  55. if isinstance(ids, (list, tuple)) and not len(ids):
  56. return []
  57. if isinstance(ids, (long, int)):
  58. ids = [ids]
  59. reads = self.read(cr, uid, ids, ['record_name','model', 'res_id'], context=context)
  60. res = []
  61. for record in reads:
  62. name = record['record_name']
  63. extended_name = ' [%s] ID %s' % (record.get('model', 'UNDEF'), record.get('res_id', 'UNDEF'))
  64. res.append((record['id'], name + extended_name))
  65. return res