Odoo Help

Welcome!

This community 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.

0

Problem with email template (SOLVED)

By
Pau Ubach
on 10/7/14, 10:02 PM 2,215 views

Hi,

I'm trying to send an email based on a template, but I'm getting errors, it fails to render whatever I write in the template:

 

2014-10-08 01:40:49,924 4788 ERROR pau_test openerp.addons.email_template.email_template: failed to render mako template value u'Whatever'
Traceback (most recent call last):
  File "E:\13_workspace\openerp7BDT\openerp\addons\email_template\email_template.py", line 99, in render_template
    result = mako_template_env.from_string(template).render(variables)
NameError: global name 'mako_template_env' is not defined
2014-10-08 01:40:49,924 4788 ERROR pau_test openerp.addons.email_template.email_template: failed to render mako template value u'\n<div style="font-family: \'Lucida Grande\', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); ">\nHola que tal    \n    </div>\n            '
Traceback (most recent call last):
  File "E:\13_workspace\openerp7BDT\openerp\addons\email_template\email_template.py", line 99, in render_template
    result = mako_template_env.from_string(template).render(variables)
NameError: global name 'mako_template_env' is not defined
2014-10-08 01:40:49,924 4788 ERROR pau_test openerp.addons.email_template.email_template: failed to render mako template value u"${object.user_id.email or ''}"
Traceback (most recent call last):
  File "E:\13_workspace\openerp7BDT\openerp\addons\email_template\email_template.py", line 99, in render_template
    result = mako_template_env.from_string(template).render(variables)
NameError: global name 'mako_template_env' is not defined
2014-10-08 01:40:49,924 4788 ERROR pau_test openerp.addons.email_template.email_template: failed to render mako template value u'false.mail@yahoo.es'
Traceback (most recent call last):
  File "E:\13_workspace\openerp7BDT\openerp\addons\email_template\email_template.py", line 99, in render_template
    result = mako_template_env.from_string(template).render(variables)
NameError: global name 'mako_template_env' is not defined
2014-10-08 01:40:49,924 4788 ERROR pau_test openerp.addons.email_template.email_template: failed to render mako template value u'any.mail@yahoo.es'
Traceback (most recent call last):
  File "E:\13_workspace\openerp7BDT\openerp\addons\email_template\email_template.py", line 99, in render_template
    result = mako_template_env.from_string(template).render(variables)
NameError: global name 'mako_template_env' is not defined

Here's the function used in python:

    def action_button_quot_to_customer(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'state': '1'})
        assert len(ids) == 1, 'This option should only be used for a single id at a time.'
        ir_model_data = self.pool.get('ir.model.data')
        try:
            template_id = ir_model_data.get_object_reference(cr, uid, 'digitexx_bdt', 'email_template_quotation')[1]
        except ValueError:
            template_id = False
        try:
            compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
        except ValueError:
            compose_form_id = False 
        
        ctx = dict(context)
        ctx.update({
            'default_model': 'bdt.quotation',
            'default_res_id': ids[0],
            'default_use_template': bool(template_id),
            'default_template_id': template_id,
            'default_composition_mode': 'comment',
            'mark_so_as_sent': True
        })
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'mail.compose.message',
            'views': [(compose_form_id, 'form')],
            'view_id': compose_form_id,
            'target': 'new',
            'context': ctx,
        }

And here's the template:

<record id="email_template_quotation" model="email.template">
            <field name="name">Quotation - Send to Customer</field>
            <field name="email_from">${object.user_id.email or ''}</field>
            <field name="subject">Whatever</field>
            <field name="email_to">false.mail@yahoo.es</field>
            <field name="model_id" ref="digitexx_bdt.model_bdt_quotation"/>
            <field name="auto_delete" eval="True"/>
            <field name="body_html"><![CDATA[
<div style="font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); ">
Hola que tal    
    </div>
            ]]></field>
        </record>

0
Pau Ubach
On 10/8/14, 12:06 AM

It was an error with Jinja2. I reinstalled it and now it works.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/7/14, 10:02 PM
Seen: 2215 times
Last updated: 3/16/15, 8:10 AM