Fix Product filtering and add kit disassembly functionality

Fixed:
- Replace is_active with status='active' for Product filtering in IncomingModelForm
- Product model uses status field instead of is_active

Added:
- Showcase field to ProductKit for tracking showcase placement
- product_kit field to Reservation for tracking kit-specific reservations
- Disassemble button in POS terminal for showcase kits
- API endpoint for kit disassembly (release reservations, mark discontinued)
- Improved reservation filtering when dismantling specific kits

Changes:
- ShowcaseManager now links reservations to specific kit instances
- POS terminal modal shows disassemble button in edit mode
- Kit disassembly properly updates stock aggregates

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-20 23:03:47 +03:00
parent d3060176c0
commit ff0756498c
11 changed files with 221 additions and 14 deletions

View File

@@ -67,6 +67,7 @@ class ShowcaseManager:
product=kit_item.product,
warehouse=warehouse,
showcase=showcase,
product_kit=product_kit,
quantity=component_quantity,
status='reserved'
)
@@ -84,6 +85,7 @@ class ShowcaseManager:
product=first_variant.product,
warehouse=warehouse,
showcase=showcase,
product_kit=product_kit,
quantity=component_quantity,
status='reserved'
)
@@ -250,10 +252,8 @@ class ShowcaseManager:
)
if product_kit:
# Если указан конкретный комплект, фильтруем резервы
# TODO: добавить связь резерва с конкретным экземпляром комплекта
# Пока освобождаем все резервы витрины
pass
# Если указан конкретный комплект, фильтруем только его резервы
reservations = reservations.filter(product_kit=product_kit)
released_count = reservations.count()
@@ -264,6 +264,11 @@ class ShowcaseManager:
'message': f'На витрине "{showcase.name}" нет активных резервов'
}
# Сохраняем список затронутых товаров и склад ДО обновления резервов
from inventory.models import Stock
affected_products = list(reservations.values_list('product_id', flat=True).distinct())
warehouse = showcase.warehouse
# Освобождаем резервы
reservations.update(
status='released',
@@ -272,13 +277,11 @@ class ShowcaseManager:
)
# Обновляем агрегаты Stock
from inventory.models import Stock
affected_products = reservations.values_list('product_id', flat=True).distinct()
for product_id in affected_products:
try:
stock = Stock.objects.get(
product_id=product_id,
warehouse=showcase.warehouse
warehouse=warehouse
)
stock.refresh_from_batches()
except Stock.DoesNotExist: