1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
from trytond.tools import escape_wildcard
class Email(metaclass=PoolMeta):
__name__ = 'ir.email'
@classmethod
def _match(cls, name, email):
pool = Pool()
User = pool.get('web.user')
yield from super()._match(name, email)
domain = ['OR']
for field in ['party.name', 'email']:
for value in [name, email]:
if value and len(value) >= 3:
domain.append(
(field, 'ilike', '%' + escape_wildcard(value) + '%'))
for user in User.search([
('email', '!=', ''),
domain,
], order=[]):
yield user.party.name if user.party else '', user.email
class EmailTemplate(metaclass=PoolMeta):
__name__ = 'ir.email.template'
@classmethod
def email_models(cls):
return super().email_models() + ['web.user']
@classmethod
def _get_address(cls, record):
pool = Pool()
User = pool.get('web.user')
address = super()._get_address(record)
if isinstance(record, User):
name = None
if record.party:
name = record.party.name
address = (name, record.email)
return address
@classmethod
def _get_language(cls, record):
pool = Pool()
User = pool.get('web.user')
language = super()._get_language(record)
if isinstance(record, User):
if record.party:
language = cls._get_language(record.party)
return language
|