[FIX] website_sale_aplicoop: Fix category filter ignoring blacklists

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.
This commit is contained in:
snt 2026-02-23 16:09:29 +01:00
parent c1226e720b
commit 7b343ef198

View file

@ -540,37 +540,41 @@ class AplicoopWebsiteSale(WebsiteSale):
get_all_children(selected_category) get_all_children(selected_category)
cat_filtered = ( _logger.info(
request.env["product.product"] "Filter: category %d (%s) - collected %d category IDs (including children): %s",
.sudo() category_id,
.search( selected_category.name,
[ len(all_category_ids),
("categ_id", "in", all_category_ids), all_category_ids,
("active", "=", True),
("product_tmpl_id.is_published", "=", True),
("product_tmpl_id.sale_ok", "=", True),
]
)
) )
# If the order restricts categories, intersect results # Count products in filtered_products that match these categories
if group_order.category_ids: before_count = len(filtered_products)
order_cat_ids = [] products_in_categories = filtered_products.filtered(
lambda p: p.categ_id.id in all_category_ids
)
def get_order_descendants(categories): _logger.info(
for cat in categories: "Filter: category %d - before filter: %d products, after filter: %d products",
order_cat_ids.append(cat.id) category_id,
if cat.child_id: before_count,
get_order_descendants(cat.child_id) len(products_in_categories),
)
get_order_descendants(group_order.category_ids) # Log categories of products that were filtered out (for debugging)
cat_filtered = cat_filtered.filtered( if len(products_in_categories) == 0 and before_count > 0:
lambda p: p.categ_id.id in order_cat_ids 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( _logger.info(
"Filter: category %d - found %d of %d", "Filter: category %d - found %d of %d total",
category_id, category_id,
len(filtered_products), len(filtered_products),
len(all_products), len(all_products),