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.

52 lines
1.9 KiB

6 years ago
6 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Sunflower IT (http://sunflowerweb.nl)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import api, fields, models
  5. class MailMessage(models.Model):
  6. _inherit = "mail.message"
  7. @api.model
  8. def _get_model_selection(self):
  9. """Get allowed models and their names."""
  10. model_objs = self.env["res.request.link"].search(
  11. [("mail_edit", "=", True)],
  12. order="name")
  13. return [(m.object, m.name) for m in model_objs]
  14. @api.one
  15. @api.onchange("destination_object_id")
  16. def change_destination_object(self):
  17. """Update some fields for the new message."""
  18. # pylint: disable=api-one-deprecated
  19. if self.destination_object_id:
  20. self.model = self.destination_object_id._name
  21. self.res_id = self.destination_object_id.id
  22. model_name = self.env["ir.model"].search([
  23. ("model", "=", self.model)]).name
  24. display_name = self.destination_object_id.display_name
  25. if model_name:
  26. display_name = "%s %s" % (model_name, display_name)
  27. self.record_name = display_name
  28. else:
  29. self.model = self.res_id = self.record_name = False
  30. destination_object_id = fields.Reference(
  31. _get_model_selection,
  32. "Destination object",
  33. help="Object where the message will be moved to")
  34. @api.model
  35. def _message_read_dict_postprocess(self, messages, message_tree):
  36. res = super(MailMessage, self)._message_read_dict_postprocess(
  37. messages, message_tree)
  38. for message_dict in messages:
  39. # Check if current user is a superuser
  40. superuser_group = 'mail_edit.group_mail_edit_superuser'
  41. message_dict.update(
  42. {'is_superuser': self.env.user.has_group(superuser_group)})
  43. return res