如何使用Xml Odoo创建电子邮件模板

时间:2016-12-07 16:14:51

标签: python xml openerp odoo-8

如何使用Xml Odoo创建电子邮件模板

<?xml version="1.0" encoding="UTF-8"?>

<openerp>

<data>
    <record id="entretien_send_email" model="email.template">
        <field name="name">Entretien Send by email</field>
        <field name="model_id" ref="model_appelsoffres_entretien"/>
        <field name="email_from">${(object.user_id.email or '')|safe}</field>
        <field name="subject">entretien</field>
        <field name="email_to">${(object.candidat.email or '')|safe}</field>
        <field name="auto_delete" eval="True" />
        <field name="subject">Your request has been submit</field>
        <field name="message"><![CDATA[
 THIS IS AN AUTOMATED EMAIL. DO NOT REPLY.

Hello,

We are here to inform you that the request [[object.candidat.nom]] est de    faire un entretien  [[object.titre_evenement]] with the following data:

    | Request - Details
    |=========================
    | Titre Evenement: [[object.titre_evenement]]
    |=========================
    | Nom Person: [[object.candidat.nom]]
    | Date Entretien: [[object.date_entretien]]
    | Heure Debut: [[object.heure_debut]]
    |=========================
    | Heure Fin: [[object.heure_fin]]


 Has not been confirmed and is closed.

 If you have any question, do not hesitate to contact your supervisor.

 Thank you!]]>
        </field>            
       </record>
      </data>
 </openerp>

在python中我有

 class entretien(models.Model):

_name='appelsoffres.entretien'

titre_evenement = fields.Char(required=True)

candidat =fields.Many2one('appelsoffres.candidature',string="Candidat",required=True)

email = fields.Char(required=True)

telephone = fields.Char(required=True)

portable = fields.Char(required=True)

    state = fields.Selection([

    ('draft', "Brouillon"),

    ('confirmed', "Rendez Vous Planifié"),

    ('done', "Terminé"),

    ('sent', "Envoyé"),

], default='draft')

@api.multi
def action_draftentretien(self):
    self.state = 'draft'

@api.multi
def action_confirmentretien(self):
    self.state = 'confirmed'

@api.multi
def action_doneentretien(self):
    self.state = 'done'

@api.multi
def send(self):
    self.state = 'sent'

    et_pool = self.pool.get('email.template')
    mail_sent = et_pool.send_mail(
    self.env.cr, 1, entretien_send_email, force_send=True,  context=self.env.context)
 entretien()

我收到了以下错误:

File "C:\Program Files (x86)\Odoo 8.0-20160222\server\.\openerp\api.py", line 266, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-

20160222\server\openerp\addons\Appelsdoffres\AppelsOffres.py", line 224, in send

ValueError: "global name 'entretien_send_email' is not defined" while evaluating u'send()'

1 个答案:

答案 0 :(得分:2)

首先确保清单文件(__openerp __。py)加载xml文件。

你的python代码应如下所示:

string.replace(/[\xa0\x00-\x09\x0b\x0c\x0e-\x1f\x7f]/g, '');