退货时的Empy列表

时间:2018-10-01 13:59:16

标签: odoo odoo-9

我的qweb报告中有这个

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

它工作正常,但是有时它返回一个空列表,然后我得到错误索引元组超出范围。我该如何避免呢?

1 个答案:

答案 0 :(得分:1)

您可以将get_routing_data的调用返回值设置为变量,并在使用前使用t-if条件检查该值,例如:

<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)"/>
相关问题