XML record with many2many field

Hi, I am trying to add some notification emails using xml records. Everything works except for the “attachments” field. How can I fill the data here? I already tried eval and ref with my attachment record id, but it does not seem to work.

<record model="notification.email" id="quote_sale_email">
            <field name="content" ref="report_sale_quote_html"/>
            <field name="recipients" search="[('name', '=', 'party'), ('model', '=', 'sale.sale')]"/>

            <field name="attachments" eval="(ref('report_sale_quote_pdf'))"/> Does not work
</record>

I also could not find any examples in the existing modules. Any help is appreciated, thanks.

As attachments is a Many2Many field you should create a record in the realation table and not use the realtion field directly.

Here is an example for the notification email module:

        <record model="notification.email" id="posted_invoice_notification">
            <field name="content" ref="report_posted_invoice_notification"/>
            <field name="recipients"
                search="[('model.model', '=', 'account.invoice'), ('name', '=', 'party')]"/>
            <field name="contact_mechanism">invoice</field>
        </record>

        <record model="notification.email.attachment" id="posted_invoice_notification_report_invoice">
            <field name="notification" ref="posted_invoice_notification"/>
            <field name="report" ref="account_invoice.report_invoice"/>
        </record>

With this definition we are adding the invoice report as attachment of a posted invoice notification.

You should be able to adapt it to your own custom implemenation.

Thank you. It works now :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.