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.

75 lines
2.5 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. ('email_from', operator, value),
  17. ('reply_to', operator, value)]
  18. if operator in expression.NEGATIVE_TERM_OPERATORS:
  19. domain = domain[2:]
  20. recs = self.env['mail.message'].search(domain)
  21. return [('id', 'in', recs.mapped('res_id'))]
  22. @api.multi
  23. def _compute_message_content(self):
  24. """ We don't really need to show any content. This field is to be
  25. used only by searches"""
  26. return ''
  27. message_content = fields.Text(
  28. string='Messages',
  29. help='Message content, to be used only in searches',
  30. compute="_compute_message_content",
  31. search='_search_message_content')
  32. _base_fields_view_get = models.BaseModel.fields_view_get
  33. @api.model
  34. def _custom_fields_view_get(self, view_id=None, view_type='form',
  35. toolbar=False, submenu=False):
  36. """
  37. Override to add message_ids field in all the objects
  38. that inherits mail.thread
  39. """
  40. # Tricky super call
  41. res = _base_fields_view_get(self, view_id=view_id, view_type=view_type,
  42. toolbar=toolbar, submenu=submenu)
  43. if view_type == 'search' and self._fields.get('message_content'):
  44. doc = etree.XML(res['arch'])
  45. res['fields'].update({
  46. 'message_content': {
  47. 'type': 'char',
  48. 'string': 'Message content',
  49. }
  50. })
  51. for node in doc.xpath("//field[1]"):
  52. # Add message_ids in search view
  53. elem = etree.Element('field', {
  54. 'name': 'message_content',
  55. })
  56. setup_modifiers(elem)
  57. node.addnext(elem)
  58. res['arch'] = etree.tostring(doc)
  59. return res
  60. models.BaseModel.fields_view_get = _custom_fields_view_get