我正在尝试在 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>
你能帮忙吗?
非常感谢
我终于得到答案了:
<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>
感谢您的帮助