您好我已经创建了新问题,但我无法收到电子邮件通知。
你是怎么做到的?
被修改
我在下面添加了一些代码,但我无法从self获取message_follower_ids来发送电子邮件。
class project_issue(osv.osv):
_inherit = 'project.issue'
_columns = {}
def create(self, cr, uid, vals, context=None):
res = super(project_issue, self).create(cr, uid, vals, context=context)
return res
更新
我更新了代码以获取关注者的电子邮件地址并成功发送了邮件,但他们转到了一封电子邮件。
它的object.name是合作伙伴的名字,但我希望它是问题名称。
def create(self, cr, uid, vals, context=None):
res = super(project_issue, self).create(cr, uid, vals, context=context)
issue = self.pool.get('project.issue').browse(cr, uid, res, context=context)
template = self.pool.get('ir.model.data').get_object(cr, uid, 'customized_project', 'email_template_customer_auto')
for follower in issue.message_partner_ids:
self.pool.get('mail.template').send_mail(cr, uid, template.id, follower.id, force_send=True, raise_exception=True, context=context)
这是一个电子邮件模板
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!--Email template-->
<record id="email_template_customer_auto" model="mail.template">
<field name="name">Send email notification for issue creation</field>
<field name="email_from">${object.company_id and object.company_id.email or ''}</field>
<field name="subject">New Issue created ${object.name}</field>
<field name="email_to">${object.email|safe}</field>
<field name="model_id" ref="model_project_issue"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.lang}</field>
<field name="body_html"><![CDATA[
"""
Write here a body of email using HTML tag.....
"""
]]>
</field>
</record>
</data>
</openerp>
答案 0 :(得分:1)
我找到了在创建问题时发送电子邮件的解决方案
from openerp.osv import osv, fields
import logging
class project_issue(osv.osv):
_inherit = 'project.issue'
_columns = {}
issue = ''
templtate = ''
def create(self, cr, uid, vals, context=None):
res = super(project_issue, self).create(cr, uid, vals, context=context)
self.issue = self.pool.get('project.issue').browse(cr, uid, res, context=context)
manager = self.issue.project_id.user_id.partner_id.id
assignTo = self.issue.user_id.partner_id.id
post_vars = {
'subject': ("Issue {} has been created".format(self.issue.name)),
'body': ("Issue {} has been created".format(self.issue.name)),
'partner_ids': [(4, manager)],
}
thread_pool = self.pool.get('mail.thread')
thread_pool.message_post(cr, uid, False,
context=context,
**post_vars)
return res