[ADD] website_sale_aplicoop: Supplier blacklist feature for group orders
- Add excluded_supplier_ids field for supplier exclusion - Filter products by main_seller_id (from product_main_seller addon) - Blacklist has absolute priority over all inclusion sources - Products with blacklisted main supplier never appear in orders - Update _get_products_for_group_order() with supplier blacklist logic - Add excluded_supplier_ids to 'Productos Excluidos' section in form view - Add comprehensive test suite (TestSupplierBlacklist class with 9 tests): * Test exclusion by main_seller_id * Test multiple supplier exclusion * Test products without main seller not affected * Test blacklist with direct product inclusion * Test blacklist priority over supplier inclusion * Test combined product and supplier blacklist * Test available_products_count with supplier blacklist - Add Spanish and Euskera translations - Update available_products_count computation to include excluded_supplier_ids - Version bump to 18.0.1.5.0 Use case: Exclude all products from specific supplier (e.g., temporary unavailability) Example: Category with 100 products, exclude supplier X → all products from X excluded Workflow: Bulk inclusion via categories + supplier-level exclusion + product-level exclusion
This commit is contained in:
parent
75ebb7b907
commit
d90f2cdc61
7 changed files with 371 additions and 4 deletions
|
|
@ -196,6 +196,15 @@ class GroupOrder(models.Model):
|
|||
tracking=True,
|
||||
help="Products explicitly excluded from this order (blacklist has absolute priority)",
|
||||
)
|
||||
excluded_supplier_ids = fields.Many2many(
|
||||
"res.partner",
|
||||
"group_order_excluded_supplier_rel",
|
||||
"order_id",
|
||||
"supplier_id",
|
||||
domain=[("supplier_rank", ">", 0)],
|
||||
tracking=True,
|
||||
help="Suppliers excluded from this order. Products with these suppliers as main seller will not be available (blacklist has absolute priority)",
|
||||
)
|
||||
|
||||
# === Estado ===
|
||||
state = fields.Selection(
|
||||
|
|
@ -241,7 +250,13 @@ class GroupOrder(models.Model):
|
|||
help="Total count of available products from all sources",
|
||||
)
|
||||
|
||||
@api.depends("product_ids", "category_ids", "supplier_ids", "excluded_product_ids")
|
||||
@api.depends(
|
||||
"product_ids",
|
||||
"category_ids",
|
||||
"supplier_ids",
|
||||
"excluded_product_ids",
|
||||
"excluded_supplier_ids",
|
||||
)
|
||||
def _compute_available_products_count(self):
|
||||
"""Count all available products from all sources."""
|
||||
for record in self:
|
||||
|
|
@ -395,17 +410,35 @@ class GroupOrder(models.Model):
|
|||
).filtered("active")
|
||||
products |= supplier_products
|
||||
|
||||
# 4) Apply blacklist filter (absolute priority)
|
||||
# 4) Apply product blacklist filter (absolute priority)
|
||||
if order.excluded_product_ids:
|
||||
excluded_count = len(products & order.excluded_product_ids)
|
||||
products = products - order.excluded_product_ids
|
||||
_logger.info(
|
||||
"Group order %d: Excluded %d products from blacklist (total available: %d)",
|
||||
"Group order %d: Excluded %d products from product blacklist (total: %d)",
|
||||
order.id,
|
||||
excluded_count,
|
||||
len(products),
|
||||
)
|
||||
|
||||
# 5) Apply supplier blacklist filter (absolute priority)
|
||||
# Exclude products whose main seller is in the excluded suppliers list
|
||||
if order.excluded_supplier_ids:
|
||||
# Filter products where main_seller_id is in excluded_supplier_ids
|
||||
excluded_by_supplier = products.filtered(
|
||||
lambda p: p.product_tmpl_id.main_seller_id
|
||||
and p.product_tmpl_id.main_seller_id in order.excluded_supplier_ids
|
||||
)
|
||||
if excluded_by_supplier:
|
||||
products = products - excluded_by_supplier
|
||||
_logger.info(
|
||||
"Group order %d: Excluded %d products from supplier blacklist (main sellers: %s) (total: %d)",
|
||||
order.id,
|
||||
len(excluded_by_supplier),
|
||||
", ".join(order.excluded_supplier_ids.mapped("name")),
|
||||
len(products),
|
||||
)
|
||||
|
||||
return products
|
||||
|
||||
def _get_products_paginated(self, order_id, page=1, per_page=20):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue