Odoo 12 为什么 Cron 正在发送电子邮件,但正文是空的?
Odoo 12 Why Cron is sending email, but body is empty?
我开发了一个 Cron,以便当一个任务的 date_deadline 等于今天时,该任务的负责用户将收到一封电子邮件。
功能还很基础,还在测试中
class ProjectTasks(models.Model):
_inherit = 'project.task'
@api.multi
def send_email(self):
print('Executing CRON')
today = date.today()
tasks = self.env['project.task'].search([('date_deadline','=',today)])
body = 'Reminder, your task %s is going to expire today' % (tasks.name)
subject = 'Reminder Task Expire Today'
email_from = self.env['ir.mail_server'].search([('id','=',1)])
email_to = tasks.user_id.email
values = {
'res_id' : 1,
'email_from' : email_from.smtp_user,
'email_to' : email_to,
'auto_delete' : False,
'model' : 'project.task',
'body' : body,
'subject' : subject,
}
send_mail = self.env['mail.mail'].sudo().create(values)
send_mail.send()
而我的 XML 是:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="ir_send_mail_task" model="ir.cron">
<field name="name">Recordatorio Vencimiento Tarea</field>
<field name="active">True</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_project_task"/>
<field name="state">code</field>
<field name="code">model.send_email()</field>
</record>
</data>
</odoo>
所以...我在这里缺少什么?我收到的是主题,但不是正文。
尝试更改您的 body 标签。
values = {
'res_id' : 1,
'email_from' : email_from.smtp_user,
'email_to' : email_to,
'auto_delete' : False,
'model' : 'project.task',
'body_html' : body,
'subject' : subject,
}
我开发了一个 Cron,以便当一个任务的 date_deadline 等于今天时,该任务的负责用户将收到一封电子邮件。
功能还很基础,还在测试中
class ProjectTasks(models.Model):
_inherit = 'project.task'
@api.multi
def send_email(self):
print('Executing CRON')
today = date.today()
tasks = self.env['project.task'].search([('date_deadline','=',today)])
body = 'Reminder, your task %s is going to expire today' % (tasks.name)
subject = 'Reminder Task Expire Today'
email_from = self.env['ir.mail_server'].search([('id','=',1)])
email_to = tasks.user_id.email
values = {
'res_id' : 1,
'email_from' : email_from.smtp_user,
'email_to' : email_to,
'auto_delete' : False,
'model' : 'project.task',
'body' : body,
'subject' : subject,
}
send_mail = self.env['mail.mail'].sudo().create(values)
send_mail.send()
而我的 XML 是:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="ir_send_mail_task" model="ir.cron">
<field name="name">Recordatorio Vencimiento Tarea</field>
<field name="active">True</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_project_task"/>
<field name="state">code</field>
<field name="code">model.send_email()</field>
</record>
</data>
</odoo>
所以...我在这里缺少什么?我收到的是主题,但不是正文。
尝试更改您的 body 标签。
values = {
'res_id' : 1,
'email_from' : email_from.smtp_user,
'email_to' : email_to,
'auto_delete' : False,
'model' : 'project.task',
'body_html' : body,
'subject' : subject,
}