Hello,
I have problem with this error that creates when I want to send a mail template when a request is approve/create.
Failed to render template <Template memory:7fdf80141b00> using values {'format_date': <function MailTemplate._render_template.<locals>.<lambda> at 0x7fdf80bb1840>, 'format_datetime': <function MailTemplate._render_template.<locals>.<lambda> at 0x7fdf80bb16a8>, 'format_amount': <function MailTemplate._render_template.<locals>.<lambda> at 0x7fdf80bb1730>, 'format_duration': <function MailTemplate._render_template.<locals>.<lambda> at 0x7fdf8019e598>, 'user': res.users(2,), 'ctx': {'lang': 'en_US', 'tz': False, 'uid': 2, 'allowed_company_ids': [1], 'params': {'action': 370, 'cids': 1, 'id': 1, 'menu_id': 254, 'model': 'sprogroup.purchase.request', 'view_type': 'form'}, 'safe': False}, 'object': sprogroup.purchase.request(1,)}
This is the mail template:
<record id="approve_email_template" model="mail.template">
<field name="name">temp_approve</field>
<field name="email_from">${object.company_id and object.company_id.email or ''}</field>
<field name="subject">Approvazione Richiesta di Acquisto</field>
<field name="email_to">${object.requested_by}</field>
<field name="lang">${object.lang}</field>
<field name="model_id" ref="sprogroup_purchase_request.model_sprogroup_purchase_request"/>
<field name="auto_delete" eval="True"/>
<field name="body_html">
<![CDATA[
<p>Gentile ${(object.requested_by)},<br/><br/>
La tua richiesta d'acquisto è stata approvata! </br>
Controlla sull'app Richiesta d'Acquisto<br/></p>
Saluti,<br/>
${(object.company_id.name)}
]]>
</field>
</record>
<record id="request_email_template" model="mail.template">
<field name="name">temp_new_request</field>
<field name="email_from">${object.company_id and object.company_id.email or ''}</field>
<field name="subject">Nuova richiesta d'acquisto</field>
<field name="email_to">${for email in object.get_groups_usesr_email():}</field>
<field name="lang">${object.lang}</field>
<field name="model_id" ref="sprogroup_purchase_request.model_sprogroup_purchase_request"/>
<field name="auto_delete" eval="True"/>
<field name="body_html">
<![CDATA[
<p>Gentile ${(object.assigned_to)},<br/><br/>
E' stata creata una nuova richiesta d'acquisto da parte di ${object.requested_by}</br>
Controlla sull'app Richiesta d'Acquisto<br/></p>
Saluti,<br/>
${(object.company_id.name)}
]]>
</field>
</record>
This is the python script:
def button_to_approve(self):
if(self.prezzo<=500):
view = self.env.ref('sh_message.sh_message_wizard')
view_id = view and view.id or False
context = dict(self._context or {})
context['message']="Richiesta inviata al Manager"
self.write({'state': 'leader_approved'})
template_rec = self.env.ref('sprogroup_purchase_request.request_email_template')
template_rec.send_mail(self.id)
return {'name':'Confermato',
'type':'ir.actions.act_window',
'view_type':'form',
'view_mode':'form',
'res_model':'sh.message.wizard',
'views':[(view.id,'form')],
'view_id':view.id,
'target':'new',
'context':context,
}
else:
template_rec = self.env.ref('sprogroup_purchase_request.request_email_template')
template_rec.send_mail(self.id)
return self.write({'state':'to_approve'})
Thanks...
Send email on button click: https://goo.gl/z16PBZ