[英]How to loop over a list of objects in Odoo 9 Qweb and get each object?
我有一个对象列表,我想遍历该列表并获取每个对象的属性。 如何遍历列表并获取列表的每个项目以获取对象字段?
您可以在QWeb中使用t-foreach
并遍历序列类型,例如列表,集合或Odoo记录集。
以下是Odoo的午餐应用程序(V10)的一个更大示例:
<tbody>
<t t-foreach="docs.read_group([('id', 'in', docs.ids)],['user_id'],['user_id'])" t-as="o">
<t t-set="user" t-value="user.browse(o['user_id'][0])"/>
<t t-set="lines" t-value="docs.search([('user_id', '=', user.id), ('id', 'in', docs.ids)])"/>
<tr>
<td colspan="2">
<strong t-field="user.name"/>
</td>
<td class="text-right" colspan="2">
<strong>
<span t-esc="sum(line.price for line in lines)"/>
<span t-field="user.company_id.currency_id.symbol"/>
</strong>
</td>
</tr>
<tr t-foreach="lines" t-as="line">
<td>
<span t-field="line.date"></span>
</td>
<td>
<span t-field="line.product_id.name"/>
</td>
<td>
<span t-field="line.note"/>
</td>
<td class="text-right">
<span t-field="line.price"
t-options='{"widget": "monetary", "display_currency": user.company_id.currency_id}'/>
</td>
</tr>
</t>
</tbody>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.