Odoo无法呈现电子邮件模板

时间:2020-07-12 17:06:54

标签: python xml odoo odoo-12 odoo-13

人们。

无论何时创建新的带有Logistics_type:Inbound的维护请求,我都试图通过电子邮件发送通知。我在这里经历了一些问题。如果我执行以下操作:操作->复制:并保存一条新记录,它基本上可以正常工作并发送电子邮件,而如果我尝试通过“创建”按钮创建新的维护记录,则无法使用以下错误代码呈现模板:< / p>

无法使用值{'format_date':,'format_tz':,'format_amount':,“用户”:res.users(2,),“ ctx”:{'email_to':“ admin@rsaworks.com”,“安全”:False},“对象”:无}

UndefinedError:“无”没有属性“ equipment_id”

我的模特:

MaintenanceRequest类(models.Model):

_inherit = 'maintenance.request'

@api.model

def create(self, vals):

    res = super(MaintenanceRequest, self).create(vals)

    vals = {}

    if res.logistics_type == 'Inbound':

        if res.message_partner_ids:

            for follower in res.message_partner_ids:

                vals.update({

                'email_to': follower.email,



                })

                template_id = self.env.ref("ssi_maintenance.maintenance_email_notification_template").id

                template = self.env['mail.template'].browse(template_id)

                template.with_context(vals).send_mail(self.id, force_send = True)

    return res

这是我的电子邮件模板:

<data>  

    <record id='maintenance_email_notification_template' model='mail.template'>

        <field name="name">Maintenance Request Created </field>

        <field name="model_id" ref = "test_maintenance.model_maintenance_request"/>

        <field name='email_from'>${object.user_id.login.email_formatted |safe}</field>

        <field name='email_to'>${ctx['email_to']}</field>

        <field name='subject'>Maintenace Request Created : ${object.name}</field>

        <field name='body_html' type='html'>

            <div style="margin: 0px; padding: 0px;">

                <p style="margin: 0px; padding: 0px; font-size: 13px">

                <p>Hey new maintenace request has been created</p>

                <br /> <br />

                Here is your detail

                <br /> <br />

                Customer : ${object.equipment_id.customer_id.name} <br />

                Equipment : ${object.equipment_id.name} <br />

                Created By : ${object.employee_id.name} <br />

                Request Date : ${object.request_date} <br />

                Scheduled Date : ${object.schedule_date} <br />

                Equipment / Rating : ${object.equipment_id.rating} <br />

                Equipment / Rating Unit : ${object.equipment_id.rating_unit} <br />

                

                <br /> <br />

                This is automatic generated email, please donot reply. If you have any question please contact admin

                </p>

            </div>

        </field>

        <field name="report_template" ref="test_maintenance.test_maintenance_logistics_report"/>

        <field name="report_name"> Maintenance Report </field>

    </record>

</data>

如果有人可以给我任何建议或帮助,我将不胜感激。预先谢谢你

0 个答案:

没有答案
相关问题