我正在尝试从我的工作流操作发送自动电子邮件。除非电子邮件正文没有填充我的objet属性,否则一切顺利。更进一步,发送的电子邮件标题中包含正确的属性。这是我的代码:
def _send_mail(self, cr, uid, ids,subject,message, context=None):
email_template_obj = self.pool.get('email.template')
template_ids = email_template_obj.search(cr, uid, [('model_id.model', '=', 'mymodule.module')])
template = email_template_obj.browse(cr, uid, template_ids[0], context=context)
complaint = self.browse(cr, uid, ids[0], context=context)
email_template_obj.send_mail(cr, uid,template_ids[0], ids[0],True, context=context)
return True
我的电子邮件模板:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Email template -->
<record id="iso9001_complaint_reject_email" model="email.template">
<field name="name">Send auto email</field>
<field name="email_from">name.lastname@gmail.com</field>
<field name="subject">Your request has been ${object.state}</field>
<field name="email_to">name.lastname@gmail.com</field>
<field name="model_id" ref="model_mymodule_module"/>
<field name="auto_delete" eval="True" />
<field name="lang">${object.lang}</field>
<field name="body_html"><![CDATA[
THIS IS AN AUTOMATED EMAIL. DO NOT REPLY.
Hello,
We are here to inform you that the request [[object.subject]] you submitted on [[object.date]] with the following data:
| Request - Details
|=========================
| Number: test
|=========================
| Responsible Person: [[object.originator_id.name]]
| request description: [[object.description]]
Has not been [[object.state]] and is closed.
If you have any question, do not hesitate to contact your supervisor.
Thank you!
]]></field>
</record>
</data>
</openerp>
为什么我收到的电子邮件标题中填写了正确的属性,但没有收到电子邮件正文?
答案 0 :(得分:0)
没关系,从论坛复制粘贴的事实有时会产生一些问题。我认为模板和报告的行为相同。在我的模板下面,我juste用$ {object.attribute}更改了[[object.attribute]],就像ine title一样。所以现在我的模板是这样的:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Email template -->
<record id="iso9001_complaint_reject_email" model="email.template">
<field name="name">Send auto email</field>
<field name="email_from">name.lastname@gmail.com</field>
<field name="subject">Your request has been ${object.state}</field>
<field name="email_to">name.lastname@gmail.com</field>
<field name="model_id" ref="model_mymodule_module"/>
<field name="auto_delete" eval="True" />
<field name="lang">${object.lang}</field>
<field name="body_html"><![CDATA[
THIS IS AN AUTOMATED EMAIL. DO NOT REPLY.
Hello,
We are here to inform you that the request ${object.subject} you submitted on ${object.date} with the following data:
| Request - Details
|=========================
| Number: test
|=========================
| Responsible Person: ${object.originator_id.name}
| request description: ${object.description}
Has not been ${object.state} and is closed.
If you have any question, do not hesitate to contact your supervisor.
Thank you!
]]></field>
</record>
</data>
</openerp>
希望这可以帮助别人。