Odoo 10: не удалось обработать почтовый шаблон - PullRequest
0 голосов
/ 13 февраля 2019

Я создал почтовый шаблон в 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>

А вот метод, который его вызывает:
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.

1 Ответ

0 голосов
/ 13 февраля 2019

Попробуйте изменить свой код следующим образом

template.send_mail (crm_lead_id.id, force_send = True, повысить_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  
...