تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
9804 أدوات العرض

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>

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

How did you reinstall jinja2, can you share the steps.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يناير 24
4119
1
مارس 21
9376
0
يناير 19
6992
0
مارس 15
3520
1
مارس 15
6753