Odoo 10:无法呈现邮件模板

时间:2019-02-13 11:48:40

标签: email templates odoo-10

我已经在Odoo 10中创建了一个邮件模板,并使用cron任务对其进行了调用。问题是它不起作用并给我错误,这里是日志:https://pastebin.com/c7zCXbxF。你可以帮帮我吗? 这是邮件模板:

<odoo>
<data>
    <record id="crm_lead_reminder" model="mail.template">
          <field name="name">Rappel sur le pipeline</field>
          <field name="email_from">admin@example.com</field>
          <field name="subject">Rappel ${object.type} ${object.name} </field>
          <field name="email_to">${object.user_id.partner_id.email}</field>
          <field name="model_id" ref="sale_cron.model_crm_lead"/>
          <field name="auto_delete" eval="True"/>
          <field name="body_html">
              <![CDATA[
                  <p>
                    hello world
                  </p>
                ]]>
          </field>
   </record>
</data>

这是调用它的方法:
    sale_cron类(models.Model):     _inherit ='crm.lead'

def _trigger_action(self, date_action, current_date):
    date_action = [int(date) for date in date_action.split('-')]
    if date_action[0] == current_date.year:
        if date_action[1] == current_date.month:
            if date_action[2] == current_date.day or date_action[2] == current_date.day + 1:
                return 0
    return -1

def _check_crm_lead(self):
    current_date = datetime.datetime.now()
    for crm_lead_id in self.search([('stage_id', '!=', 4)]):
        i = self._trigger_action(crm_lead_id.date_action, current_date)
        if i == -1:
            return 0
        template = self.env.ref('sale_cron.crm_lead_reminder')
        template.send_mail(self.user_id.id, force_send=True, raise_exception=True)
    return 1  

ps:模块名称为sale_cron。

1 个答案:

答案 0 :(得分:0)

尝试像这样更改代码

template.send_mail(crm_lead_id.id,force_send = True,raise_exception = True)

def _check_crm_lead(self):
    current_date = datetime.datetime.now()
    for crm_lead_id in self.search([('stage_id', '!=', 4)]):
        i = self._trigger_action(crm_lead_id.date_action, current_date)
        if i == -1:
            return 0
        template = self.env.ref('sale_cron.crm_lead_reminder')
        template.send_mail(crm_lead_id.id, force_send=True, raise_exception=True)
    return 1