- Add total_available, total_reserved, total_free annotations to product queries - Display free stock (green/red) with reserved count in product list - Show detailed stock info in product detail page (moved to top) - Make reservation count clickable to view filtered reservations - Add product filter support to ReservationListView - Add product link in reservation list for easy navigation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
Reservation (Резервирование товара) views - READ ONLY
|
||
Резервы управляются только через POS и Orders
|
||
"""
|
||
from django.views.generic import ListView
|
||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||
from ..models import Reservation
|
||
from products.models import Product
|
||
|
||
|
||
class ReservationListView(LoginRequiredMixin, ListView):
|
||
"""
|
||
Список резервирований (только для просмотра).
|
||
Управление резервами происходит через POS (витринные комплекты) и Orders.
|
||
"""
|
||
model = Reservation
|
||
template_name = 'inventory/reservation/reservation_list.html'
|
||
context_object_name = 'reservations'
|
||
paginate_by = 20
|
||
|
||
def get_queryset(self):
|
||
"""Показываем все резервы со статусом 'reserved', с опциональной фильтрацией по товару"""
|
||
queryset = Reservation.objects.filter(
|
||
status='reserved'
|
||
).select_related('product', 'warehouse', 'order_item', 'showcase', 'product_kit').order_by('-reserved_at')
|
||
|
||
# Фильтрация по товару
|
||
product_id = self.request.GET.get('product')
|
||
if product_id:
|
||
queryset = queryset.filter(product_id=product_id)
|
||
|
||
return queryset
|
||
|
||
def get_context_data(self, **kwargs):
|
||
context = super().get_context_data(**kwargs)
|
||
# Если фильтруем по товару, добавляем его в контекст
|
||
product_id = self.request.GET.get('product')
|
||
if product_id:
|
||
try:
|
||
context['filtered_product'] = Product.objects.get(pk=product_id)
|
||
except Product.DoesNotExist:
|
||
pass
|
||
return context
|