Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

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

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
mailv8emailtemplateemail_template
4 Replies
11030 Tampilan
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
Buang
Aleksander Nøkland
Penulis

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
Penulis Jawaban Terbai

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
Buang
Avatar
Chris Mann
Jawaban Terbai

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
Buang
Avatar
Muhammad Salman Khan
Jawaban Terbai

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
Buang
Avatar
Qutechs, Ahmed M.Elmubarak
Jawaban Terbai

Hello,

Try this one:

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

I hope it'll help,


Regards

0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
[v.8] How to add new fields to email
mail email emailtemplate email_template
Avatar
0
Apr 16
5299
Email catchall reply to Odoo V8 Diselesaikan
mail v8
Avatar
Avatar
Avatar
Avatar
Avatar
11
Apr 23
35742
link to online version email template
emailtemplate email_template
Avatar
0
Feb 23
2144
Email templates are broken, show code instead the codes traduction. Diselesaikan
emailtemplate email_template
Avatar
1
Mei 22
3200
Email template formula for Subscription
emailtemplate email_template
Avatar
0
Mei 21
2962
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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