Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to send Partner Mass Mail to partner and parters contacts, v8.

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
mailv8emailtemplateemail_template
4 Respuestas
10986 Vistas
Avatar
Aleksander Nøkland

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.

0
Avatar
Descartar
Aleksander Nøkland
Autor

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="<%", block_end_string="%>", variable_start_string="${", variable_end_string="}", comment_start_string="<%doc>", comment_end_string="%doc>", line_statement_prefix="%", line_comment_prefix="##", trim_blocks=True, # do not output newline after blocks autoescape=True, # XML/HTML automatic escaping ) mako_template_env.globals.update({ 'str': str, 'quote': quote, 'urlencode': urlencode, 'datetime': datetime, 'len': len, 'abs': abs, 'min': min, 'max': max, 'sum': sum, 'filter': filter, 'reduce': reduce, 'map': map, 'round': round, # dateutil.relativedelta is an old-style class and cannot be directly # instanciated wihtin a jinja2 expression, so a lambda "proxy" is # is needed, apparently. 'relativedelta': lambda *a, **kw : relativedelta.relativedelta(*a, **kw), }) except ImportError: _logger.warning("jinja2 not available, templating features will not work!") class email_template(osv.osv): _inherit = 'email.template' def render_template_batch(self, cr, uid, template, model, res_ids, context=None, post_process=False): """Render the given template text, replace mako expressions ``${expr}`` with the result of evaluating these expressions with an evaluation context containing: * ``user``: browse_record of the current user * ``object``: browse_record of the document record this mail is related to * ``context``: the context passed to the mail composition wizard :param str template: the template text to render :param str model: model name of the document record this mail is related to. :param int res_ids: list of ids of document records those mails are related to. """ if context is None: context = {} res_ids = filter(None, res_ids) # to avoid browsing [None] below results = dict.fromkeys(res_ids, u"") # try to load the template try: template = mako_template_env.from_string(tools.ustr(template)) except Exception: _logger.exception("Failed to load template %r", template) return results # prepare template variables user = self.pool.get('res.users').browse(cr, uid, uid, context=context) def _do_loop(loop, field): return ','.join(map(str,[x[field] for x in loop])) records = self.pool[model].browse(cr, uid, res_ids, context=context) or [None] variables = { 'format_tz': lambda dt, tz=False, format=False, context=context: format_tz(self.pool, cr, uid, dt, tz, format, context), 'user': user, 'ctx': context, # context kw would clash with mako internals 'LOOP': _do_loop, } for record in records: res_id = record.id if record else None variables['object'] = record try: render_result = template.render(variables) except Exception: _logger.exception("Failed to render template %r using values %r" % (template, variables)) render_result = u"" if render_result == u"False": render_result = u"" results[res_id] = render_result if post_process: for res_id, result in results.iteritems(): results[res_id] = self.render_post_process(cr, uid, result, context=context) return results

Avatar
Aleksander Nøkland
Autor Mejor respuesta

Thank you for the suggestion, but when I try to use this:

${object.mapped('child_ids.email')}

The system creates new partners with name and email like this: myreal@address.com&#39
It does this for all the contacts on the partner I send to.

Then this fails of course with the following error:

 SMTPRecipientsRefused: {'"myreal@address.com&#39"': (501, '5.1.3 Invalid address'), 'myreal@address.com&#39': (501, '5.1.3 Invalid address')}

2015-11-12 09:41:32,884 30493 ERROR demodb openerp.addons.mail.mail_mail: failed sending mail.mail 117


EDIT:

I've solved this, i think.

The LOOP-part was not in v7, but part of a custom module in v7.

I've ported/created a quick and dirty 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:
     from jinja2.sandbox import SandboxedEnvironment
     mako_template_env = SandboxedEnvironment(
         block_start_string="<%",
         block_end_string="%>",
         variable_start_string="${",
         variable_end_string="}",
         comment_start_string="<%doc>",
         comment_end_string="</%doc>",
         line_statement_prefix="%",
         line_comment_prefix="##",
         trim_blocks=True, # do not output newline after blocks
         autoescape=True, # XML/HTML automatic escaping
     )
     mako_template_env.globals.update({
         'str': str,
         'quote': quote,
         'urlencode': urlencode,
         'datetime': datetime,
         'len': len,
         'abs': abs,
         'min': min,
         'max': max,
         'sum': sum,
         'filter': filter,
         'reduce': reduce,
         'map': map,
         'round': round,
        'relativedelta': lambda *a, **kw : relativedelta.relativedelta(*a, **kw),
     })
except ImportError:
     _logger.warning("jinja2 not available, templating features will not work!")
class email_template(osv.osv):
     _inherit = 'email.template'
     def render_template_batch(self, cr, uid, template, model, res_ids, context=None, post_process=False):
    if context is None:
         context = {}
     res_ids = filter(None, res_ids) # to avoid browsing [None] below
     results = dict.fromkeys(res_ids, u"")
    # try to load the template
     try:
        template = mako_template_env.from_string(tools.ustr(template))
 except Exception:
     _logger.exception("Failed to load template %r", template)
     return results
     # prepare template variables
     user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
    def _do_loop(loop, field):
         return ','.join(map(str,[x[field] for x in loop]))
     records = self.pool[model].browse(cr, uid, res_ids, context=context) or [None]
     variables = {
         'format_tz': lambda dt, tz=False, format=False, context=context: format_tz(self.pool, cr, uid, dt, tz, format, context),
         'user': user,
         'ctx': context, # context kw would clash with mako internals
         'LOOP': _do_loop,
    }
     for record in records:
         res_id = record.id if record else None
         variables['object'] = record
         try:
             render_result = template.render(variables)
        except Exception:
            _logger.exception("Failed to render template %r using values %r" % (template, variables))
             render_result = u""
         if render_result == u"False":
             render_result = u""
         results[res_id] = render_result
     if post_process:
         for res_id, result in results.iteritems():
             results[res_id] = self.render_post_process(cr, uid, result, context=context)
     return results

0
Avatar
Descartar
Avatar
Chris Mann
Mejor respuesta

Just found the answer to this in Odoo V14 having experienced the same.

${ str(object.mapped('partner_id.parent_id.child_ids.email') if object.partner_id.parent_id else object.mapped('partner_id.child_ids.email')).replace("'","") }

Or for Odoo V15

{{ str(object.mapped('partner_id.parent_id.child_ids.email') if object.partner_id.parent_id else object.mapped('partner_id.child_ids.email')).replace("'","") }}


0
Avatar
Descartar
Avatar
Muhammad Salman Khan
Mejor respuesta

I Tried this one:

${object.mapped('child_ids.name')}

it worked great But getting in this format like : [u'ABCname', u'XYZname']

It should be like: ABCname XYZname

Can you please help  Ahmed M.Elmubarak 

Thanks.

0
Avatar
Descartar
Avatar
Qutechs, Ahmed M.Elmubarak
Mejor respuesta

Hello,

Try this one:

${object.mapped('child_ids.email')}

I hope it'll help,


Regards

0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
[v.8] How to add new fields to email
mail email emailtemplate email_template
Avatar
0
abr 16
5260
Email catchall reply to Odoo V8 Resuelto
mail v8
Avatar
Avatar
Avatar
Avatar
Avatar
11
abr 23
35674
link to online version email template
emailtemplate email_template
Avatar
0
feb 23
2127
Email templates are broken, show code instead the codes traduction. Resuelto
emailtemplate email_template
Avatar
1
may 22
3165
Email template formula for Subscription
emailtemplate email_template
Avatar
0
may 21
2943
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now