如何在Odoo 9 Qweb中循环访问对象列表并获取每个对象



我有一个对象列表,我想遍历这个列表并获取每个对象的属性。应该如何遍历列表并获取列表中的每个项目以获取对象字段?

您可以在

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>

最新更新