如何在Odoo中创建电子邮件通知功能? [英] How to create email notification function in Odoo?
问题描述
我有calender.event
模块.因为我有一个日期字段ending_date
.我想在结束日期超过当前日期时创建函数,它将向所有员工发送通知.
I have calender.event
module. In that I have one date field ending_date
. I wanted to create function when ending date exceeds current date it should send notification to all employees.
此函数在calender.event继承的文件中
This function at calender.event inherited file
def send_birthday_email(self, cr, uid, ids=None, context=None):
sobj = self.pool.get('calendar.event').browse(cr,uid,ids,context=context)
ir_model_data = self.pool.get('ir.model.data')
template_obj = self.pool.get('email.template')
cc_text = ''
if sobj.attendee_ids:
for cc_obj in sobj.attendee_ids:
if cc_obj.email:
cc_text += cc_obj.email + ','
for rec in sobj:
template_id = ir_model_data.get_object_reference(cr,uid,'calander_extended', 'calendar_notify')[1]
self.pool.get('email.template').write(cr,uid,template_id,{'email_to' : cc_text,})
self.pool.get('email.template').send_mail(cr,uid,template_id,rec.id,force_send=True,context=context)
return True
这是为此编写的电子邮件模板
This is email template written for it
<?xml version="1.0"?>
<openerp>
<data>
<record id="calendar_notify" model="email.template">
<field name="name">Email Notification</field>
<field name="email_from">${object.event_id.user_id.email or ''}</field>
<field name="subject">${object.event_id.name}</field>
<field name="model_id" ref="calander_extended.model_calendar_event"/>
<field name="email_to" >${('' if object.partner_id and object.partner_id.email and object.partner_id.email==object.email else object.email|safe)}</field>
<field name="partner_to">${object.partner_id and object.partner_id.email and object.partner_id.email==object.email and object.partner_id.id or False }</field>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>${object.event_id.name}</title>
<style>
span.oe_mail_footer_access {
display:block;
text-align:center;
color:grey;
}
</style>
</head>
<body>
<div style="border-radius: 2px; max-width: 1200px; height: auto;margin-left: auto;margin-right: auto;background-color:#f9f9f9;">
<div style="height:auto;text-align: center;font-size : 30px;color: #8A89BA;">
<strong>${object.event_id.name}</strong>
</div>
</div>
</body>
</html>
]]>
</field>
</record>
</data>
</openerp>
当我通过单击按钮调用该功能时,它不会出现任何错误.但是也没有收到邮件给与会者
When i invoke that function by clicking button then its not getting any error .but no getting mail also to attendees
推荐答案
您可以创建cron,就像日历模块所做的一样[1]:
You can create a cron, as the calendar module does [1]:
<record forcecreate="True" id="ir_cron_scheduler_alarm" model="ir.cron">
<field name="name">Run Event Reminder</field>
<field eval="False" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">30</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field eval="'calendar.alarm_manager'" name="model" />
<field eval="'get_next_mail'" name="function" />
<!--<field eval="'(False,)'" name="args" />-->
</record>
在这种情况下,正在calendar.alarm_manager
模型上调用方法get_next_mail
.使用您的方法,您可以做任何您想做的事情.另外,该模型看起来像是通过扩展代码来放置代码的正确位置.
In this case is calling the method get_next_mail
on calendar.alarm_manager
model. In your method you can do whatever you want. Also, this model looks like the right place where to put your code by extending it.
[1] https://github.com/OCA /OCB/blob/9.0/addons/calendar/calendar_cron.xml
这篇关于如何在Odoo中创建电子邮件通知功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!