Odoo - QWeb - Accessing relational fields in qweb reports ?

Zarshed Ali
Zarshed Ali
| 2 1 2
Asked on 2/17/15, 5:51 AM

Odoo provides a simple qweb syntax for accessing model data field values inside reports:

<span t-field="o.fieldname"/>

where o is the Odoo model the report is connected to and fieldname the name of the corresponding field of this model.

When you want to access a field from another connected model you can simply append a “.” (point) to enter the next deeper level of model data, e.g.:

<span t-field="o.many2one_connection.field_of_connected_model"/>

It is possible to nest an unlimited number of connected fields to reach any data you want.

Example 1: let’s say you have a picking list and want to show the description for each product. The right way to implement this in your report is:

<span t-field="o.pack_operation.product_id.product_tmpl_id.description"/>

Explanation: product_id gives you the id of the connected product.product model record. This record includes another id called product_tmpl_id to connected to the given product.templatemodel record. Inside this product.template record you finally find the product’s description field.

Example 2: let’s say you have an invoice for a partner who uses a different address than its company. But you want to use the company address on this invoice.

<span t-field="o.partner_id.parent_id.street"/>

Explanation: partner_id gives you the many2one connection to the customer of this invoice.parent_id leads to the master company of this customer. street is now the address of the master company and not the address of the invoice’s customer.

Zarshed Ali
Zarshed Ali
| 2 1 2
Answered on 2/17/15, 5:52 AM

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

2 follower(s)


Asked: 2/17/15, 5:51 AM
Seen: 5341 times
Last updated: 2/17/15, 5:52 AM