Fix cart lock validation and error handling improvements

## 1. Add cart lock validation to sell_from_showcase()
- Prevent selling showcase kits locked in another cashier's cart
- Check cart_lock_expires_at before allowing direct sales
- Return clear error message with lock holder's name and time remaining
- File: inventory/services/showcase_manager.py

## 2. Improve error handling in POS create_temp_kit_to_showcase()
- Add detailed logging for all error types (JSON, validation, generic)
- Provide user-friendly error messages instead of generic 500
- Log full context (kit name, showcase ID, items, user) for debugging
- Categorize errors: stock issues, integrity, locks, not found
- File: pos/views.py

## 3. Fix critical bug in create_temporary_kit()
- Replace non-existent is_active field with status='active'
- Affects 3 locations: kit creation, product lookup, kit duplication
- This was causing 500 errors when creating temporary kits from order edit
- File: products/services/kit_service.py

## 4. Improve error handling in create_temporary_kit_api()
- Add comprehensive logging for order creation endpoint
- Provide specific error messages for common failure scenarios
- Help diagnose issues when creating kits from order editing UI
- File: products/views/api_views.py

These changes complete the Soft Lock system and fix the 500 error issue.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-21 00:24:59 +03:00
parent 33e33ecbac
commit 08a5527ba7
7 changed files with 135 additions and 16 deletions

View File

@@ -57,7 +57,7 @@ def create_temporary_kit(
name=name.strip(),
description=description.strip() if description else '',
is_temporary=True,
is_active=True,
status='active',
order=order,
price_adjustment_type='none'
)
@@ -72,7 +72,7 @@ def create_temporary_kit(
continue
try:
product = Product.objects.get(pk=product_id, is_active=True)
product = Product.objects.get(pk=product_id, status='active')
KitItem.objects.create(
kit=kit,
product=product,
@@ -135,7 +135,7 @@ def duplicate_kit(kit: ProductKit, new_name: Optional[str] = None) -> ProductKit
price_adjustment_value=kit.price_adjustment_value,
sale_price=kit.sale_price,
is_temporary=False, # Копия всегда постоянная
is_active=kit.is_active
status=kit.status
)
# Копируем категории