Search code examples
odooodoo-9

Empy list on return


I have this in my qweb report

 <span t-esc="formatLang(get_routing_data(o)[-1]['total'] , digits=3)"/>

it works ok, but sometimes it returns an empty list and then i get error index tuple out of range. how can i avoid it?


Solution

  • You could set the return value of the call to get_routing_data into a variable and make check the value using t-if conditions before use it, like:

    <t t-set="routing_data" t-value="get_routing_data(o)"/>
    <span t-if="routing_data and len(routing_data) > 0 and routing_data[-1].get('total', False)" t-esc="formatLang(routing_data[-1]['total'], digits=3)"/>