Arthur Fortin
Arthur Fortin

Reputation: 181

Loop through a group list with Qweb in Odoo17

I'm trying to display a list of products group by category on a Qweb Report in Odoo17. I created my list in a python class. After the process, this python list looks like this :

{
    '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'}
    ]
}

On the Qweb side I loop through this list to display the name of products after the category. I return the category but can't figure out how display the products related to each category :

<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>

Could you please help ?

Thanks a lot

Upvotes: 1

Views: 101

Answers (1)

Arthur Fortin
Arthur Fortin

Reputation: 181

I finally get the answer :

<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>

Thanks for your help

Upvotes: 1

Related Questions