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.

67 lines
2.3 KiB

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