Identify the QWeb template used for the invoice report. In this case, it would be the template with the report_invoice_document name. You can locate the template in the Odoo source code or search for it in your Odoo custom modules.
Override the QWeb template to include the delivery reference
- Create a new template extension to add the necessary code. Here an example:
odoo>
data>
template id="custom_invoice_document_inherit" inherit_id="account.report_invoice_document">
xpath expr="//template[@id='account.report_invoice_document']" position="replace">
template>
xpath expr="//td[@class='trt-data text-right']" position="after">
td class="trt-data">
Delivery Reference: o.picking_ids.mapped('name').join(', ')"/>
/td>
/xpath>
/template>
/xpath>
/template>
/data>
In the above example, the custom_invoice_document template extends the account.report_invoice_document template. It adds a new td element after the existing ones, displaying the delivery reference using the o.picking_ids field. The mapped('name').join(', ') expression retrieves the name field value from the picking_ids and joins them with a comma.
Make sure to include the XML file in your custom module's manifest file