Add shipping address to invoice in Odoo 9 SA
The use case is this - you have a customer who has multiple shipping addresses and a single billing address. You send them invoices from Odoo but they require the billing address and the location to which the product they are paying for was shipped.
This is something that plagued me for a while. It seems like it should be so simple, but it’s definitely not designed to be an immediate function. The issue is that there is no reference to the shipping address in the account.invoice model, and the only place that reference exists is in the sale.order model. However, there is no reference by ID to the sale.order record in the account.invoice model, only by reference which is a string such as “SO1234″. This means you have to look up the sales order by matching the reference string to the sales order name field.
What I have found is somewhat of a hack, but it works! In the QWeb view for the account.invoice (account.report_invoice_document ) report add the following snippet where you want your address.
<t t-if="o.origin">
<t t-set="order" t-value="request.env['sale.order'].search([('name', '=', o.origin)], limit=1)"/>
<t t-if="order">
<span t-field="order.partner_shipping_id" t-field-options="{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true, "phone_icons": true}"/>
</t>
</t>
What this does is checks to see if an ‘origin’ value exists in the account.invoice record and then searches the “name” field of the sale.order model for a match and returns the first one. Then if there is a match, it grabs the record and uses the “partner_shipping_id” field and puts that into the contact widget (which is looking for a res.partner id) and outputs the Name, Address and Phone from that record. It’s pretty hackish, but definitely does the job.