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.

62 lines
2.1 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, 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. """
  14. Override to add message_ids field in all the objects
  15. that inherits mail.thread
  16. """
  17. # Tricky super call
  18. res = _base_fields_view_get(self, view_id=view_id, view_type=view_type,
  19. toolbar=toolbar, submenu=submenu)
  20. if view_type == 'search' and self._fields.get('message_ids'):
  21. doc = etree.XML(res['arch'])
  22. for node in doc.xpath("//field[1]"):
  23. # Add message_ids in search view
  24. elem = etree.Element('field', {
  25. 'name': 'message_ids',
  26. 'domain': "[('model','=', %s)]" % self._model
  27. })
  28. node.addnext(elem)
  29. # Register message_ids in fields
  30. res['fields'].update({
  31. 'message_ids': {
  32. 'type': 'one2many',
  33. 'relation': 'mail.message',
  34. 'string': 'Messages',
  35. }
  36. })
  37. res['arch'] = etree.tostring(doc)
  38. return res
  39. models.BaseModel.fields_view_get = _custom_fields_view_get
  40. class MailMessage(models.Model):
  41. _inherit = 'mail.message'
  42. @api.model
  43. def name_search(self, name='', args=None, operator='ilike', limit=100):
  44. """Override to search on multiple fields"""
  45. args = args or []
  46. domain = ['|', '|', ('record_name', operator, name),
  47. ('subject', operator, name), ('body', operator, name)]
  48. if operator in expression.NEGATIVE_TERM_OPERATORS:
  49. domain = domain[2:]
  50. rec = self.search(domain + args, limit=limit)
  51. return rec.name_get()