Odoo 10:无法呈现邮件模板

问题描述 投票:0回答:1

我在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">[email protected]</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>

以下是称之为的方法: class 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。

email templates odoo-10
1个回答
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  
© www.soinside.com 2019 - 2024. All rights reserved.