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.

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