在 Odoo17 中使用 Qweb 循环浏览群组列表

问题描述 投票:0回答:1

我正在尝试在 Odoo17 的 Qweb 报告上按类别显示产品列表。我在 python 类中创建了我的列表。处理完成后,这个 python 列表如下所示:

{
    'Office Furniture': 
    [
        {'name': 'Chair floor protection\nOffice chairs can harm your floor: protect it.', 'cat': 'Office Furniture'}, 
        {'name': 'Chair floor protection\nOffice chairs can harm your floor: protect it.', 'cat': 'Office Furniture'}
    ], 
    'Services': 
    [
        {'name': 'Deposit', 'cat': 'Services'}
    ]
}

在 Qweb 端,我循环浏览此列表以在类别后显示产品名称。我返回了类别,但不知道如何显示与每个类别相关的产品:

<div>
    <t t-foreach="data['purchases']" t-as="category">
        <p>
            <!-- Display the category : WORKS FINE -->
            <span t-esc="category" />
            <t t-foreach="category" t-as="product">
                <!-- Display the product : HOW ? -->
            </t>
        </p>
    </t>
</div>

你能帮忙吗?

非常感谢

python odoo qweb
1个回答
0
投票

我终于得到答案了:

<t t-foreach="data['products']" t-as="category">
    <b>
        <span t-esc="category" />
    </b>
    <t t-foreach="data['products'][category]" t-as="prod">
        <p><span t-esc="prod['name']" /></p>
    </t>
</t>

感谢您的帮助

© www.soinside.com 2019 - 2024. All rights reserved.