I’m setting a trigger to send an email when doing a specific workflow or setting a flag in a model. In notification email module, all recipients are Many2One fields. I just want to use the trigger to send an email to an internal department of the company: accouting@company.com, sales@company.com,…
Fallback user recipient field is only displayed if the recipient field is used.
How to allow such internal emails as recipients ?
Thanks.
I made a custo on notification email module to add a “recipient email” field for such trigger that send an email to a specific department of the company.
from trytond.i18n import gettext
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.tools.email_ import EmailNotValidError, validate_email
from .exceptions import EMailValidationError
class Email(metaclass=PoolMeta):
__name__ = 'notification.email'
recipient_email = fields.Char("Recipient Email",
help="Will take priority over recipients fields if filled")
def _get_to(self, record):
pool = Pool()
Lang = pool.get('ir.lang')
to, languages = super()._get_to(record)
if self.recipient_email:
try:
validate_email(self.recipient_email)
except EmailNotValidError as e:
raise EMailValidationError(gettext(
'puck.msg_email_invalid',
record=record.rec_name,
email=self.recipient_email),
str(e)) from e
languages = Lang.search([('code', '=', 'fr'),], limit=1)
languages = set(languages)
to = self._get_addresses(self.recipient_email)
return to, languages
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="//label[@name='recipients']" position="before">
<label name="recipient_email"/>
<field name="recipient_email"/>
<newline/>
</xpath>
</data>