Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
mailv8emailtemplateemail_template
4 Odpovědi
11032 Zobrazení
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
Zrušit
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 Nejlepší odpověď

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
Zrušit
Avatar
Chris Mann
Nejlepší odpověď

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
Zrušit
Avatar
Muhammad Salman Khan
Nejlepší odpověď

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
Zrušit
Avatar
Qutechs, Ahmed M.Elmubarak
Nejlepší odpověď

Hello,

Try this one:

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

I hope it'll help,


Regards

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
[v.8] How to add new fields to email
mail email emailtemplate email_template
Avatar
0
dub 16
5300
Email catchall reply to Odoo V8 Vyřešeno
mail v8
Avatar
Avatar
Avatar
Avatar
Avatar
11
dub 23
35755
link to online version email template
emailtemplate email_template
Avatar
0
úno 23
2145
Email templates are broken, show code instead the codes traduction. Vyřešeno
emailtemplate email_template
Avatar
1
kvě 22
3206
Email template formula for Subscription
emailtemplate email_template
Avatar
0
kvě 21
2962
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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