From 7b343ef19874f731fe0b5ea3fd0542f570a828ff Mon Sep 17 00:00:00 2001 From: snt Date: Mon, 23 Feb 2026 16:09:29 +0100 Subject: [PATCH] [FIX] website_sale_aplicoop: Fix category filter ignoring blacklists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical fix for category filter in product discovery: - BREAKING BUG: Category filter was doing a new search() that completely ignored product/supplier/category blacklists - FIX: Now filters from filtered_products (which has blacklists applied) instead of doing a fresh search() from database - This ensures blacklist rules are ALWAYS respected Added detailed logging for debugging empty category results: - Log collected category IDs (including children) - Log before/after product counts - If result is empty, log sample product categories to help debug - Helps identify configuration issues vs code bugs This fixes user report: 'no muestra ningĂșn producto' in some categories The issue was that filtered products were being replaced with a fresh search that bypassed all blacklist filters. --- .../controllers/website_sale.py | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) 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),