Files
octopus/myproject/check_kit_bindings.py
Andrey Smakotin 29859503a7 Enforce parameter binding requirement for ConfigurableKitProduct variants
Changes:
1. Removed unused attributesMetadata container from configurablekit_form.html
   - Dead code from old formset-based attribute system
   - 10 lines of unused HTML and templating removed

2. Enhanced formset validation in BaseConfigurableKitOptionFormSet.clean():
   - If product HAS parameters: variants MUST select values for ALL parameters
   - If product HAS NO parameters: variants MUST NOT be created
   - Error message guides user to add parameters first

Business logic:
- ConfigurableKitProduct variants (options) are ALWAYS bound to attribute values
- You cannot create orphan variants without parameter selections
- Each variant must have a value for every product parameter

User experience:
- Clear error message if trying to add variant without parameters
- Enforces proper product structure: parameters first, then variants

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 21:46:58 +03:00

28 lines
1.1 KiB
Python

#!/usr/bin/env python
import os, sys, django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
django.setup()
from products.models.kits import ConfigurableKitProduct
from django_tenants.utils import tenant_context
from tenants.models import Client
client = Client.objects.get(schema_name='grach')
with tenant_context(client):
print("=" * 80)
print("ConfigurableKitProduct items with kit bindings:")
print("=" * 80)
for product in ConfigurableKitProduct.objects.all().order_by('-id')[:5]:
attrs = product.parent_attributes.all()
if attrs.exists():
kit_bound = attrs.filter(kit__isnull=False).count()
print(f"\nID {product.id}: {product.name}")
print(f" Total attrs: {attrs.count()} | Kit-bound: {kit_bound}")
for param_name in attrs.values_list('name', flat=True).distinct():
vals = attrs.filter(name=param_name)
print(f" {param_name}:")
for attr in vals:
kit = attr.kit.name if attr.kit else "(no kit)"
print(f" - {attr.option} -> {kit}")