sms_template.py 999 B

1234567891011121314151617181920212223
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, models
  4. from odoo.osv import expression
  5. class SmsTemplate(models.Model):
  6. _inherit = 'sms.template'
  7. @api.model
  8. def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
  9. """Context-based hack to filter reference field in a m2o search box to emulate a domain the ORM currently does not support.
  10. As we can not specify a domain on a reference field, we added a context
  11. key `filter_template_on_event` on the template reference field. If this
  12. key is set, we add our domain in the `args` in the `_name_search`
  13. method to filtrate the SMS templates.
  14. """
  15. if self.env.context.get('filter_template_on_event'):
  16. args = expression.AND([[('model', '=', 'event.registration')], args])
  17. return super(SmsTemplate, self)._name_search(name, args, operator, limit, name_get_uid)