Skip to Content
Menu
This question has been flagged

Hello,

In Odoo the default language in reports is the partner language.

What I need to do is to add only one field and its translation in the same  report

i.e let's say in order/quotation report, I want to present the product name with two languages english and french  in the same quotation. How can I achieve that

Avatar
Discard
Author

Update:

Here's a sample of my code in xml file:

<thead>

<tr>

<th>Product</th>

<th></th>

<th></th>

<th>Description</th>

<th>Description in French</th>

</tr>

</thead>

<tbody>

<t t-foreach="layout_category['lines']" t-as="line">

<tr t-attf-class="product-description row-{{line_parity}}">

<td style="padding:20px;" t-foreach="line.product_id" t-as="pro">

<span t-field="pro.avatar.image" t-field-options='{"widget": "image","class": "oe_avatar"}' style="padding:20px;"/>

</td>

<td></td>

<td></td>

<td class="colored">

<p t-field="line.name"/>

</td>

<td class="colored">

<p t-field="line.name" t-field-options='{"lang": "fr_FR"}'/>

</td>

</tr>

</t>

</tbody>

Best Answer

Try in your report template to add or pass context:

object.with_context({'lang':'en_US'}).name

So, just add the same field twice but with different context

Avatar
Discard
Author

Hi, can you give me an example please.

I submitted a new comment with a sample of my code in xml file

In this line <p t-field="line.name" t-field-options='{"lang": "fr_FR"}'/>

I was trying to pass the language in t-field-options but it didn't work

Try tp:

<p t-field="line.with_context({'lang': 'fr_FR'}).name"/>

Author

it didn't work

Strange. Where does it lead? Is there an error?

Author

No errors as well.. Is there any alternative way to do it.. or at least can you just help me to understand the way to achieve it

The way above should work. No idea, why it doesn't work. Are you sure name has translation on French? Another alternative is to pre-define methods before genereting a report to pass a correct value. But you should use the same "with_context"

instead of t-field try t-esc or t-raw

Related Posts Replies Views Activity
0
Apr 17
1786
1
Jun 17
2167
0
May 24
1393
1
Aug 23
28077
2
Dec 23
11087