Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10075 Lượt xem

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>

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 24
4375
1
thg 3 21
9595
0
thg 1 19
7160
0
thg 3 15
3665
1
thg 3 15
6955