如何在 Odoo 16 中继承和更新现有邮件模板

 在本文中,让我们看看如何在 Odoo 16 中继承和编辑现有邮件模板。我们必须这样做才能对现有模板的内容进行任何调整或更新。让我们考虑一个在会计模块中更新邮件模板的示例。

 单击“account.move”模型中的“发送并打印”按钮后,将打开上述向导。在这里,我们将进行更改。从向导中可以清楚地看到使用的模板名称是“发票:发送”。让我们搜索代码。

<?xml version="1.0" ?>
<odoo>
    <!-- Mail template are declared in a NOUPDATE block
         so users can freely customize/delete them -->
    <data noupdate="1">
        <!--Email template -->
        <record id="email_template_edi_invoice" model="mail.template">
            <field name="name">Invoice: Sending</field>
            <field name="model_id" ref="account.model_account_move"/>
            <field name="email_from">{{ (object.invoice_user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
            <field name="partner_to">{{ object.partner_id.id }}</field>
            <field name="subject">{{ object.company_id.name }} Invoice (Ref {{ object.name or 'n/a' }})</field>
            <field name="description">Sent to customers with their invoices in attachment</field>
            <field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
    <p style="margin: 0px; padding: 0px; font-size: 13px;">
        Dear
        <t t-if="object.partner_id.parent_id">
            <t t-out="object.partner_id.name or ''">Brandon Freeman</t> (<t t-out="object.partner_id.parent_id.name or ''">Azure Interior</t>),
        </t>
        <t t-else="">
            <t t-out="object.partner_id.name or ''">Brandon Freeman</t>,
        </t>
        <br /><br />
        Here is your
        <t t-if="object.name">
            invoice <span style="font-weight:bold;" t-out="object.name or ''">INV/2021/05/0005</span>
        </t>
        <t t-else="">
            invoice
        </t>
        <t t-if="object.invoice_origin">
            (with reference: <t t-out="object.invoice_origin or ''">SUB003</t>)
        </t>
        amounting in <span style="font-weight:bold;" t-out="format_amount(object.amount_total, object.currency_id) or ''">$ 143,750.00</span>
        from <t t-out="object.company_id.name or ''">YourCompany</t>.
        <t t-if="object.payment_state in ('paid', 'in_payment')">
            This invoice is already paid.
        </t>
        <t t-else="">
            Please remit payment at your earliest convenience.
            <t t-if="object.payment_reference">
                <br /><br />
                Please use the following communication for your payment: <span style="font-weight:bold;" t-out="object.payment_reference or ''">INV/2021/05/0005</span>.
            </t>
        </t>
        <br /><br />
        Do not hesitate to contact us if you have any questions.
        <t t-if="not is_html_empty(object.invoice_user_id.signature)">
            <br /><br />
            <t t-out="object.invoice_user_id.signature or ''">--<br/>Mitchell Admin</t>
        </t>
    </p>
</div>
            </field>
            <field name="report_template" ref="account_invoices"/>
            <field name="report_name">Invoice_{{ (object.name or '').replace('/','_') }}{{ object.state == 'draft' and '_draft' or '' }}</field>
            <field name="lang">{{ object.partner_id.lang }}</field>
            <field name="auto_delete" eval="True"/>
        </record>
        <record id="mail_template_data_payment_receipt" model="mail.template">
            <field name="name">Payment: Payment Receipt</field>
            <field name="model_id" ref="account.model_account_payment"/>
            <field name="subject">{{ object.company_id.name }} Payment Receipt (Ref {{ object.name or 'n/a' }})</field>
            <field name="partner_to">{{ object.partner_id.id }}</field>
            <field name="description">Sent manually to customer when clicking on 'Send receipt by email' in payment action</field>
            <field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
    <p style="margin: 0px; padding: 0px; font-size: 13px;">
        Dear <t t-out="object.partner_id.name or ''">Azure Interior</t><br/><br/>
        Thank you for your payment.
        Here is your payment receipt <span style="font-weight:bold;" t-out="(object.name or '').replace('/','-') or ''">BNK1-2021-05-0002</span> amounting
        to <span style="font-weight:bold;" t-out="format_amount(object.amount, object.currency_id) or ''">$ 10.00</span> from <t t-out="object.company_id.name or ''">YourCompany</t>.
        <br/><br/>
        Do not hesitate to contact us if you have any questions.
        <br/><br/>
        Best regards,
        <t t-if="not is_html_empty(user.signature)">
            <br/><br/>
            <t t-out="user.signature or ''">--<br/>Mitchell Admin</t>
        </t>
    </p>
</div>
</field>
            <field name="report_template" ref="account.action_report_payment_receipt"/>
            <field name="report_name">{{ (object.name or '').replace('/','-') }}</field>
            <field name="lang">{{ object.partner_id.lang }}</field>
            <field name="auto_delete" eval="True"/>
        </record>
        <!-- Credit note template -->
        <record id="email_template_edi_credit_note" model="mail.template">
            <field name="name">Credit Note: Sending</field>
            <field name="model_id" ref="account.model_account_move"/>
            <field name="email_from">{{ (object.invoice_user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
            <field name="partner_to">{{ object.partner_id.id }}</field>
            <field name="subject">{{ object.company_id.name }} Credit Note (Ref {{ object.name or 'n/a' }})</field>
            <field name="description">Sent to customers with the credit note in attachment</field>
            <field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
    <p style="margin: 0px; padding: 0px; font-size: 13px;">
        Dear
        <t t-if="object.partner_id.parent_id">
            <t t-out="object.partner_id.name or ''">Brandon Freeman</t> (<t t-out="object.partner_id.parent_id.name or ''">Azure Interior</t>),
        </t>
        <t t-else="">
            <t t-out="object.partner_id.name or ''">Brandon Freeman</t>,
        </t>
        <br /><br />
        Here is your
        <t t-if="object.name">
            credit note <span style="font-weight:bold;" t-out="object.name or ''">RINV/2021/05/0001</span>
        </t>
        <t t-else="">
            credit note
        </t>
        <t t-if="object.invoice_origin">
            (with reference: <t t-out="object.invoice_origin or ''">SUB003</t>)
        </t>
        amounting in <span style="font-weight:bold;" t-out="format_amount(object.amount_total, object.currency_id) or ''">$ 143,750.00</span>
        from <t t-out="object.company_id.name or ''">YourCompany</t>.
        <br /><br />
        Do not hesitate to contact us if you have any questions.
        <t t-if="not is_html_empty(object.invoice_user_id.signature)">
            <br /><br />
            <t t-out="object.invoice_user_id.signature or ''">--<br/>Mitchell Admin</t>
        </t>
    </p>
</div>
            </field>
            <field name="report_template" ref="account_invoices"/>
            <field name="report_name">Credit_note_{{ (object.name or '').replace('/','_') }}{{ object.state == 'draft' and '_draft' or '' }}</field>
            <field name="lang">{{ object.partner_id.lang }}</field>
            <field name="auto_delete" eval="True"/>
        </record>
    </data>
</odoo>

 这是现有代码。这里,由于存在关键字 noupdate = “1”,因此记录不可更新。因此,为了进行修改,我们需要将其更改为可更新。为此,我们可以使用函数和值标签。

<function name="write" model="ir.model.data">
    <function name="search" model="ir.model.data">
        <value eval="[('name', '=', 'email_template_edi_invoice'), ('module', '=', 'account')]" />
    </function>
    <value eval="{'noupdate': False}" />
</function>

这里的“email_template_edi_invoice”是现有的记录ID。首先,我们搜索这个电子邮件模板并将no_update值写入False。这将帮助我们在电子邮件模板中进行更改。

现在我们可以对电子邮件模板进行必要的更改。例如,我将发票日期包含在电子邮件的主题中,并将报告的名称附加到电子邮件中。我们必须编辑邮件模板记录的主题和报告名称字段才能执行此操作。因为我们将从自定义模块更新它们,所以请提供模块名称以及记录 ID。在我们的案例中,邮件模板位于“帐户”模块中。因此,我们必须指定 ID“account.email_template_edi_invoice”。

<record id="account.email_template_edi_invoice" model="mail.template">
    <field name="subject">{{ object.company_id.name }} Invoice (Ref {{ object.name or 'n/a' }}) {{ object.invoice_date }}</field>
    <field name="report_name">Invoice_{{ (object.name or '').replace('/', '_') }}{{ object.state == 'draft' and '_draft' or '' }}_{{ object.invoice_date.strftime('%Y_%m_%d') }}</field>
</record>
After we make the adjustments, we must return the noupdate to True for the record.
<function name="write" model="ir.model.data">
    <function name="search" model="ir.model.data">
        <value eval="[('name', '=', 'email_template_edi_invoice'), ('module', '=', 'account')]" />
    </function>
    <value eval="{'noupdate': True}" />
</function>

我们所做的和一开始做的一样。但是,我们将使用搜索和写入功能来查找邮件模板记录,然后将“noupdate”设置为 True。这将有助于避免对邮件模板进行不必要的更改。此代码必须放在自定义模块数据目录中的 XML 文件中。我们必须在数据参数中指定文件,并在清单文件的“依赖项”列表中指定现有模板的模块(在此示例中为“account”,因为我们正在升级“email_template_edi_invoice 模板”)。

我们可以通过这种方式继承和更新 Odoo 和其他自定义模块中现有的电子邮件模板。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奔跑的蜗牛..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值