تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1542 أدوات العرض

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


Could you please help ?

Thanks a lot

الصورة الرمزية
إهمال
أفضل إجابة

Hi,
 def get_grouped_products(self):
        products = self.env['product.product'].search([])  # Fetch all products
        grouped_products = {}
        for product in products:
            category = product.categ_id.name  # Access category name
            if category not in grouped_products:
                grouped_products[category] = []
            grouped_products[category].append(product)
        return grouped_products

Hope it helps

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thank so much !

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 25
1670
1
مايو 25
1662
1
أبريل 25
2258
1
فبراير 25
1545
0
أكتوبر 24
1303