mirror of
https://github.com/bringout/oca-ocb-mail.git
synced 2026-04-20 12:02:00 +02:00
Initial commit: Mail packages
This commit is contained in:
commit
4e53507711
1948 changed files with 751201 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class SmsTemplate(models.Model):
|
||||
_inherit = 'sms.template'
|
||||
|
||||
@api.model
|
||||
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
|
||||
"""Context-based hack to filter reference field in a m2o search box to emulate a domain the ORM currently does not support.
|
||||
|
||||
As we can not specify a domain on a reference field, we added a context
|
||||
key `filter_template_on_event` on the template reference field. If this
|
||||
key is set, we add our domain in the `args` in the `_name_search`
|
||||
method to filtrate the SMS templates.
|
||||
"""
|
||||
if self.env.context.get('filter_template_on_event'):
|
||||
args = expression.AND([[('model', '=', 'event.registration')], args])
|
||||
return super(SmsTemplate, self)._name_search(name, args, operator, limit, name_get_uid)
|
||||
|
||||
def unlink(self):
|
||||
res = super().unlink()
|
||||
domain = ('template_ref', 'in', [f"{template._name},{template.id}" for template in self])
|
||||
self.env['event.mail'].sudo().search([domain]).unlink()
|
||||
self.env['event.type.mail'].sudo().search([domain]).unlink()
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue