Odoo Help

0
4 Answers
0
Aleksander Nøkland
11/12/15, 7:00 AM

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="         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
Muhammad Salman Khan
6/10/18, 8:30 AM

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
--Qutechs, Ahmed M.Elmubarak--


Qutechs, Ahmed M.Elmubarak
11/12/15, 2:42 AM

Hello,

Try this one:

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

I hope it'll help,


Regards

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now