diff --git a/website_sale_aplicoop/controllers/website_sale.py b/website_sale_aplicoop/controllers/website_sale.py index fb78819..0510e30 100644 --- a/website_sale_aplicoop/controllers/website_sale.py +++ b/website_sale_aplicoop/controllers/website_sale.py @@ -540,37 +540,41 @@ class AplicoopWebsiteSale(WebsiteSale): get_all_children(selected_category) - cat_filtered = ( - request.env["product.product"] - .sudo() - .search( - [ - ("categ_id", "in", all_category_ids), - ("active", "=", True), - ("product_tmpl_id.is_published", "=", True), - ("product_tmpl_id.sale_ok", "=", True), - ] - ) + _logger.info( + "Filter: category %d (%s) - collected %d category IDs (including children): %s", + category_id, + selected_category.name, + len(all_category_ids), + all_category_ids, ) - # If the order restricts categories, intersect results - if group_order.category_ids: - order_cat_ids = [] + # Count products in filtered_products that match these categories + before_count = len(filtered_products) + products_in_categories = filtered_products.filtered( + lambda p: p.categ_id.id in all_category_ids + ) - def get_order_descendants(categories): - for cat in categories: - order_cat_ids.append(cat.id) - if cat.child_id: - get_order_descendants(cat.child_id) + _logger.info( + "Filter: category %d - before filter: %d products, after filter: %d products", + category_id, + before_count, + len(products_in_categories), + ) - get_order_descendants(group_order.category_ids) - cat_filtered = cat_filtered.filtered( - lambda p: p.categ_id.id in order_cat_ids + # Log categories of products that were filtered out (for debugging) + if len(products_in_categories) == 0 and before_count > 0: + product_categories = set() + for p in filtered_products[:10]: # Only first 10 to avoid spam + product_categories.add((p.categ_id.id, p.categ_id.name)) + _logger.warning( + "Filter: category %d - ALL PRODUCTS FILTERED OUT! Sample product categories: %s", + category_id, + list(product_categories), ) - filtered_products = cat_filtered + filtered_products = products_in_categories _logger.info( - "Filter: category %d - found %d of %d", + "Filter: category %d - found %d of %d total", category_id, len(filtered_products), len(all_products),