refactor: подготовка к стандартизации Transfer моделей
Текущее состояние перед рефакторингом Transfer → TransferDocument. Все изменения с последнего коммита по улучшению системы поступлений. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from .warehouse import WarehouseListView, WarehouseCreateView, WarehouseUpdateView, WarehouseDeleteView, SetDefaultWarehouseView
|
||||
from .batch import IncomingBatchListView, IncomingBatchDetailView, StockBatchListView, StockBatchDetailView
|
||||
from .batch import StockBatchListView, StockBatchDetailView
|
||||
from .sale import SaleListView, SaleCreateView, SaleUpdateView, SaleDeleteView, SaleDetailView
|
||||
from .inventory_ops import (
|
||||
InventoryListView, InventoryCreateView, InventoryDetailView,
|
||||
@@ -57,8 +57,6 @@ __all__ = [
|
||||
'inventory_home',
|
||||
# Warehouse
|
||||
'WarehouseListView', 'WarehouseCreateView', 'WarehouseUpdateView', 'WarehouseDeleteView', 'SetDefaultWarehouseView',
|
||||
# IncomingBatch
|
||||
'IncomingBatchListView', 'IncomingBatchDetailView',
|
||||
# Sale
|
||||
'SaleListView', 'SaleCreateView', 'SaleUpdateView', 'SaleDeleteView', 'SaleDetailView',
|
||||
# Inventory
|
||||
|
||||
@@ -1,47 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Batch views - READ ONLY
|
||||
- IncomingBatch (Партии поступлений)
|
||||
- StockBatch (Партии товара на складе)
|
||||
|
||||
ПРИМЕЧАНИЕ: IncomingBatch и Incoming удалены. Используйте IncomingDocument вместо них.
|
||||
"""
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from ..models import IncomingBatch, Incoming, StockBatch, SaleBatchAllocation, WriteOff
|
||||
|
||||
|
||||
class IncomingBatchListView(LoginRequiredMixin, ListView):
|
||||
"""Список всех партий поступлений товара"""
|
||||
model = IncomingBatch
|
||||
template_name = 'inventory/incoming_batch/batch_list.html'
|
||||
context_object_name = 'batches'
|
||||
paginate_by = 30
|
||||
|
||||
def get_queryset(self):
|
||||
return IncomingBatch.objects.all().select_related('warehouse').order_by('-created_at')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
# Добавляем количество товаров в каждую партию
|
||||
for batch in context['batches']:
|
||||
batch.items_count = batch.items.count()
|
||||
batch.total_quantity = sum(item.quantity for item in batch.items.all())
|
||||
return context
|
||||
|
||||
|
||||
class IncomingBatchDetailView(LoginRequiredMixin, DetailView):
|
||||
"""Детальная информация по партии поступления"""
|
||||
model = IncomingBatch
|
||||
template_name = 'inventory/incoming_batch/batch_detail.html'
|
||||
context_object_name = 'batch'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
batch = self.get_object()
|
||||
|
||||
# Товары в этой партии
|
||||
context['items'] = batch.items.all().select_related('product', 'stock_batch')
|
||||
|
||||
return context
|
||||
from ..models import StockBatch, SaleBatchAllocation, WriteOff
|
||||
|
||||
|
||||
class StockBatchListView(LoginRequiredMixin, ListView):
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.shortcuts import render
|
||||
from django.db.models import Q, Sum, Count
|
||||
from inventory.models import StockBatch, Stock, Reservation, Sale, SaleBatchAllocation, WriteOff, WriteOffDocument, WriteOffDocumentItem
|
||||
from inventory.models import (
|
||||
StockBatch, Stock, Reservation, Sale, SaleBatchAllocation, WriteOff,
|
||||
WriteOffDocument, WriteOffDocumentItem, IncomingDocument, IncomingDocumentItem
|
||||
)
|
||||
from orders.models import Order
|
||||
from products.models import Product
|
||||
from inventory.models import Warehouse
|
||||
@@ -44,6 +47,9 @@ def debug_inventory_page(request):
|
||||
writeoff_document_items = WriteOffDocumentItem.objects.select_related(
|
||||
'product', 'document__warehouse'
|
||||
).order_by('-id')
|
||||
# Документы поступления
|
||||
incoming_documents = IncomingDocument.objects.select_related('warehouse', 'created_by', 'confirmed_by').order_by('-date', '-created_at')
|
||||
incoming_document_items = IncomingDocumentItem.objects.select_related('product', 'document__warehouse').order_by('-id')
|
||||
orders = Order.objects.prefetch_related('items').order_by('-created_at')
|
||||
|
||||
# Применяем фильтры
|
||||
@@ -56,6 +62,7 @@ def debug_inventory_page(request):
|
||||
allocations = allocations.filter(sale__product_id=product_id)
|
||||
writeoffs = writeoffs.filter(batch__product_id=product_id)
|
||||
writeoff_document_items = writeoff_document_items.filter(product_id=product_id)
|
||||
incoming_document_items = incoming_document_items.filter(product_id=product_id)
|
||||
orders = orders.filter(items__product_id=product_id).distinct()
|
||||
else:
|
||||
product = None
|
||||
@@ -96,6 +103,8 @@ def debug_inventory_page(request):
|
||||
writeoffs = writeoffs.filter(batch__warehouse_id=warehouse_id)
|
||||
writeoff_documents = writeoff_documents.filter(warehouse_id=warehouse_id)
|
||||
writeoff_document_items = writeoff_document_items.filter(document__warehouse_id=warehouse_id)
|
||||
incoming_documents = incoming_documents.filter(warehouse_id=warehouse_id)
|
||||
incoming_document_items = incoming_document_items.filter(document__warehouse_id=warehouse_id)
|
||||
else:
|
||||
warehouse = None
|
||||
|
||||
@@ -108,6 +117,8 @@ def debug_inventory_page(request):
|
||||
writeoffs = writeoffs[:100]
|
||||
writeoff_documents = writeoff_documents[:50]
|
||||
writeoff_document_items = writeoff_document_items[:100]
|
||||
incoming_documents = incoming_documents[:50]
|
||||
incoming_document_items = incoming_document_items[:100]
|
||||
orders = orders[:50]
|
||||
|
||||
# Списки для фильтров
|
||||
@@ -123,6 +134,8 @@ def debug_inventory_page(request):
|
||||
'writeoffs': writeoffs,
|
||||
'writeoff_documents': writeoff_documents,
|
||||
'writeoff_document_items': writeoff_document_items,
|
||||
'incoming_documents': incoming_documents,
|
||||
'incoming_document_items': incoming_document_items,
|
||||
'orders': orders,
|
||||
'products': products,
|
||||
'warehouses': warehouses,
|
||||
|
||||
Reference in New Issue
Block a user