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.

73 lines
2.4 KiB

8 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Eficent Business and IT Consulting Services S.L.
  3. # (http://www.eficent.com)
  4. # © 2016 Serpent Consulting Services Pvt. Ltd. (<http://www.serpentcs.com>)
  5. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  6. from openerp import api, fields, models
  7. from lxml import etree
  8. from openerp.osv import expression
  9. from openerp.osv.orm import setup_modifiers
  10. class MailThread(models.AbstractModel):
  11. _inherit = 'mail.thread'
  12. def _search_message_content(self, operator, value):
  13. domain = [('model', '=', self._name), '|', '|',
  14. ('record_name', operator, value),
  15. ('subject', operator, value), ('body', operator, value)]
  16. if operator in expression.NEGATIVE_TERM_OPERATORS:
  17. domain = domain[2:]
  18. recs = self.env['mail.message'].search(domain)
  19. return [('id', 'in', recs.mapped('res_id'))]
  20. @api.multi
  21. def _compute_message_content(self):
  22. """ We don't really need to show any content. This field is to be
  23. used only by searches"""
  24. return ''
  25. message_content = fields.Text(
  26. string='Messages',
  27. help='Message content, to be used only in searches',
  28. compute="_compute_message_content",
  29. search='_search_message_content')
  30. _base_fields_view_get = models.BaseModel.fields_view_get
  31. @api.model
  32. def _custom_fields_view_get(self, view_id=None, view_type='form',
  33. toolbar=False, submenu=False):
  34. """
  35. Override to add message_ids field in all the objects
  36. that inherits mail.thread
  37. """
  38. # Tricky super call
  39. res = _base_fields_view_get(self, view_id=view_id, view_type=view_type,
  40. toolbar=toolbar, submenu=submenu)
  41. if view_type == 'search' and self._fields.get('message_content'):
  42. doc = etree.XML(res['arch'])
  43. res['fields'].update({
  44. 'message_content': {
  45. 'type': 'char',
  46. 'string': 'Message content',
  47. }
  48. })
  49. for node in doc.xpath("//field[1]"):
  50. # Add message_ids in search view
  51. elem = etree.Element('field', {
  52. 'name': 'message_content',
  53. })
  54. setup_modifiers(elem)
  55. node.addnext(elem)
  56. res['arch'] = etree.tostring(doc)
  57. return res
  58. models.BaseModel.fields_view_get = _custom_fields_view_get