I'm trying to send mail to my partners and their contacts, and I am wondering what I should set in the "To Emails"-field on the template.
I've set a filter to only display the partners (without contacts), I select the partners, click "More" and "Partner Mass Mailing", and selects a template.
In the template (Settings > Technical > Email > Templates) i fill in the field To (Emails) as follows:
${LOOP(object.child_ids,'email')},${object.email}
In v7, this works.
In v8, i get the following error:
2015-11-10 19:37:44,182 30493 ERROR demodb openerp.addons.email_template.email_template: Failed to render template <Template memory:7f895252f110> using values {'format_tz': <function <lambda> at 0x7f89382487d0>, 'ctx': {'default_template_id': 1, 'uid': 1, 'mail_server_id': 1, 'mail_notify_user_signature': False, 'default_use_template': True, 'default_composition_mode': 'mass_mail', 'default_partner_to': "${object.id or ''}", 'search_disable_custom_filters': True, 'tpl_partners_only': True, 'active_id': 828, 'lang': 'nb_NO', 'tz': False, 'active_model': 'res.partner', 'params': {'action': 93}, 'mail_auto_delete': False, 'active_ids': [828]}, 'user': res.users(1,), 'object': res.partner(828,)}
Traceback (most recent call last):
File "/opt/odoo/odoo-server/addons/email_template/email_template.py", line 201, in render_template_batch
render_result = template.render(variables)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "<template>", line 1, in top-level template code
File "/usr/lib/python2.7/dist-packages/jinja2/sandbox.py", line 354, in call
if not __self.is_safe_callable(__obj):
File "/usr/lib/python2.7/dist-packages/jinja2/sandbox.py", line 283, in is_safe_callable
return not (getattr(obj, 'unsafe_callable', False) or
UndefinedError: 'LOOP' is undefined
If I try to use:
${object.child_ids.email}
i get the following error:
2015-11-10 20:47:18,506 30493 ERROR demodb openerp.addons.email_template.email_template: Failed to render template <Template memory:7f8952453410> using values {'format_tz': <function <lambda> at 0x7f895204c758>, 'ctx': {'default_template_id': 1, 'uid': 1, 'mail_server_id': 1, 'mail_notify_user_signature': False, 'default_use_template': True, 'default_composition_mode': 'mass_mail', 'default_partner_to': "${object.id or ''}", 'search_disable_custom_filters': True, 'tpl_partners_only': True, 'active_id': 828, 'lang': 'nb_NO', 'tz': False, 'active_model': 'res.partner', 'params': {'action': 93}, 'mail_auto_delete': False, 'active_ids': [828]}, 'user': res.users(1,), 'object': res.partner(828,)}
Traceback (most recent call last):
File "/opt/odoo/odoo-server/addons/email_template/email_template.py", line 201, in render_template_batch
render_result = template.render(variables)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "<template>", line 1, in top-level template code
File "/usr/lib/python2.7/dist-packages/jinja2/sandbox.py", line 330, in getattr
value = getattr(obj, attribute)
File "/opt/odoo/odoo-server/openerp/fields.py", line 807, in __get__
record.ensure_one()
File "/opt/odoo/odoo-server/openerp/models.py", line 5268, in ensure_one
raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: res.partner(829, 830)')
Am i missing some python library? Can I use something else in the To Emails field? Any and all help is appreciated.
The LOOP-part was not in v7, but part of a custom module in v7. I've ported/created a module that inherits email_template. I've ported/created a module that inherits email_template With this we can use: ${LOOP(object.child_ids,'email')},${object.email} _init__.py : import email_template __openerp.py__ : { 'name' : 'Email Templates LOOP', 'version' : '1.0', 'author' : 'Random', 'website' : 'http://www.google.com', 'category' : 'Marketing', 'depends' : ['mail','email_template'], 'description': """ Email Templating - hack for doing loop on partner ============================================================================== Usage: On email template, in field To Email use: ${LOOP(object.child_ids,'email')} """, 'data': [ ], 'demo': [], 'installable': True, 'auto_install': False, } email_template.py : # -*- coding: utf-8 -*- import base64 import datetime import dateutil.relativedelta as relativedelta import logging import lxml import urlparse import openerp from openerp import SUPERUSER_ID from openerp.osv import osv, fields from openerp import tools, api from openerp.tools.translate import _ from urllib import urlencode, quote as quote _logger = logging.getLogger(__name__) try: # We use a jinja2 sandboxed environment to render mako templates. # Note that the rendering does not cover all the mako syntax, in particular # arbitrary Python statements are not accepted, and not all expressions are # allowed: only "public" attributes (not starting with '_') of objects may # be accessed. # This is done on purpose: it prevents incidental or malicious execution of # Python code that may break the security of the server. from jinja2.sandbox import SandboxedEnvironment mako_template_env = SandboxedEnvironment( block_start_string="", variable_start_string="${", variable_end_string="}", comment_start_string="