Search code examples
odooodoo-9

Dynamic string based on condition


In qweb report I have this code:

<span t-if="o.currency_id.name == 'USD'">
                            <th style="width: 12%;" class="text-right"><t>Unit Price ( USD )</t><br/>Unit Price (USD)</th>
                            <th style="width: 12%;" class="text-right"><t>Amount ( USD ) </t><br/>Amount (USD) <span t-esc="get_currency_codes()"/></th>
                        </span>
                        <span t-if="o.currency_id.name == 'EUR'">
                            <th style="width: 12%;" class="text-right"><t>Unit Price ( EUR )</t><br/>Unit Price (EUR)</th>
                            <th style="width: 12%;" class="text-right"><t>Amount ( EUR ) </t><br/>Amount (EUR) <span t-esc="get_currency_codes()"/></th>
                        </span>

But how can I make string dynamic according to currency?


Solution

  • This will allow you to set dynamic currency name. <span t-field="o.currency_id.name"/>

    You may try with this:

    <th style="width: 12%;" class="text-right">
        <t>Unit Price (<span t-field="o.currency_id.name"/>)</t><br/>
        Unit Price (<span t-field="o.currency_id.name"/>)
    </th>
    <th style="width: 12%;" class="text-right">
        <t>Amount (<span t-field="o.currency_id.name"/>)</t><br/>
        Amount (<span t-field="o.currency_id.name"/>) <span t-esc="get_currency_codes()"/>
    </th>