[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:
parent
c1226e720b
commit
7b343ef198
1 changed files with 28 additions and 24 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue