[ADD] website_sale_aplicoop: Category blacklist with recursive exclusion

- Add comprehensive test suite for excluded_category_ids
- 9 tests covering: single category, recursive subcategories,
  parent exclusion, direct product override, unrelated categories,
  empty blacklist, multiple exclusions, combined blacklists,
  available_products_count validation
- Update UI to show excluded_category_ids in 'Productos Excluidos'
- Bump version to 18.0.1.6.0
- Update CHANGELOG with category blacklist documentation

Technical notes:
- Category blacklist was already implemented in model/logic
- This commit adds missing tests and documentation
- Recursive exclusion via get_all_excluded_descendants()
- Blacklist has absolute priority over all inclusion sources
This commit is contained in:
snt 2026-02-22 23:04:33 +01:00
parent d90f2cdc61
commit c1226e720b
7 changed files with 413 additions and 1 deletions

View file

@ -205,6 +205,14 @@ class GroupOrder(models.Model):
tracking=True,
help="Suppliers excluded from this order. Products with these suppliers as main seller will not be available (blacklist has absolute priority)",
)
excluded_category_ids = fields.Many2many(
"product.category",
"group_order_excluded_category_rel",
"order_id",
"category_id",
tracking=True,
help="Categories excluded from this order. Products in these categories and all their subcategories will not be available (blacklist has absolute priority)",
)
# === Estado ===
state = fields.Selection(
@ -256,6 +264,7 @@ class GroupOrder(models.Model):
"supplier_ids",
"excluded_product_ids",
"excluded_supplier_ids",
"excluded_category_ids",
)
def _compute_available_products_count(self):
"""Count all available products from all sources."""
@ -439,6 +448,35 @@ class GroupOrder(models.Model):
len(products),
)
# 6) Apply category blacklist filter (absolute priority)
# Exclude products in excluded categories and all their subcategories (recursive)
if order.excluded_category_ids:
# Collect all excluded category IDs including descendants
excluded_cat_ids = []
def get_all_excluded_descendants(categories):
"""Recursively collect all excluded category IDs including children."""
for cat in categories:
excluded_cat_ids.append(cat.id)
if cat.child_id:
get_all_excluded_descendants(cat.child_id)
get_all_excluded_descendants(order.excluded_category_ids)
# Filter products whose category is in the excluded list
excluded_by_category = products.filtered(
lambda p: p.categ_id.id in excluded_cat_ids
)
if excluded_by_category:
products = products - excluded_by_category
_logger.info(
"Group order %d: Excluded %d products from category blacklist (categories: %s, including subcategories) (total: %d)",
order.id,
len(excluded_by_category),
", ".join(order.excluded_category_ids.mapped("name")),
len(products),
)
return products
def _get_products_paginated(self, order_id, page=1, per_page=20):