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.

54 lines
1.9 KiB

  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, models
  7. from lxml import etree
  8. from openerp.osv import expression
  9. _base_fields_view_get = models.BaseModel.fields_view_get
  10. @api.model
  11. def _custom_fields_view_get(self, view_id=None, view_type='form',
  12. toolbar=False, submenu=False):
  13. # Tricky super call
  14. res = _base_fields_view_get(self, view_id=view_id, view_type=view_type,
  15. toolbar=toolbar, submenu=submenu)
  16. if view_type == 'search' and self._fields.get('message_ids'):
  17. doc = etree.XML(res['arch'])
  18. for node in doc.xpath("//field[1]"):
  19. elem = etree.Element('field', {
  20. 'name': 'message_ids',
  21. 'domain': "[('model','=', %s)]" % self._model
  22. })
  23. node.addnext(elem)
  24. res['fields'].update({
  25. 'message_ids': {
  26. 'type': 'many2one',
  27. 'relation': 'mail.message',
  28. 'string': 'Messages',
  29. }
  30. })
  31. res['arch'] = etree.tostring(doc)
  32. return res
  33. models.BaseModel.fields_view_get = _custom_fields_view_get
  34. class MailMessage(models.Model):
  35. _inherit = 'mail.message'
  36. @api.model
  37. def name_search(self, name='', args=None, operator='ilike', limit=100):
  38. args = args or []
  39. domain = ['|', '|', ('record_name', operator, name),
  40. ('subject', operator, name), ('body', operator, name)]
  41. if operator in expression.NEGATIVE_TERM_OPERATORS:
  42. domain = domain[2:]
  43. rec = self.search(domain + args, limit=limit)
  44. return rec.name_get()