1
0
forked from erp-dev/erp

feat: auto complete stock change

This commit is contained in:
2025-11-10 09:01:25 +08:00
parent 37c2e7d723
commit b2078dfa46
82 changed files with 1071 additions and 1336 deletions

View File

@@ -4,6 +4,14 @@ from django.utils.safestring import mark_safe
from . import models, services
class StockAdminBase(admin.ModelAdmin):
"""库存管理基础类,定义通用配置"""
def get_list_filter(self, request):
result = super().get_list_filter(request)
result = list(result) + ['created_at']
return result
@admin.register(models.PurchaseOrder)
class PurchaseOrderAdmin(admin.ModelAdmin):
list_display = ('id', 'supplier', 'order_date', 'total_amount')
@@ -13,7 +21,7 @@ class PurchaseOrderAdmin(admin.ModelAdmin):
@admin.register(models.Inventory)
class InventoryAdmin(admin.ModelAdmin):
class InventoryAdmin(StockAdminBase):
list_display = (
'id',
'product',
@@ -22,12 +30,20 @@ class InventoryAdmin(admin.ModelAdmin):
'quantity',
'num_of_rolls',
'minimum_quantity',
'frozen_quantity',
'updated_at',
)
search_fields = ('product__name', 'warehouse__name')
list_filter = ('warehouse',)
ordering = ('-updated_at',)
@admin.display(description='冻结中数量')
def frozen_quantity(self, obj):
return services.get_frozen_stock_count(
product_id=obj.product_id,
warehouse_id=obj.warehouse_id
)
@admin.display(description='颜色')
def product_color(self, obj):
return obj.product.color
@@ -45,7 +61,7 @@ class StockSnapshotAdmin(admin.ModelAdmin):
'stock_change_record',
'created_at',
)
search_fields = ('product__name', 'warehouse__name', 'stock_change_record__id')
search_fields = ('product', 'warehouse', 'stock_change_record__id')
list_filter = ('stock_change_record__type',)
ordering = ('-created_at', )
@@ -73,12 +89,17 @@ class StockChangeDetailAdmin(admin.ModelAdmin):
'stock_change_record',
'product',
'quantity',
'direction',
'unit',
)
search_fields = ('stock_change_record__id', 'product__name')
list_filter = ('stock_change_record', 'stock_change_record__type')
ordering = ('-created_at',)
@admin.display(description='出入方向')
def direction(self, obj):
return '入库' if obj.stock_change_record.is_incoming else '出库'
@admin.register(models.StockChangeRecord)
class StockChangeRecordAdmin(admin.ModelAdmin):
@@ -131,4 +152,29 @@ class StockChangeRecordAdmin(admin.ModelAdmin):
]
return mark_safe('<br>'.join(detail_list))
actions = [make_selected_stock_changes_completed]
actions = [make_selected_stock_changes_completed]
@admin.register(models.StockFreeze)
class StockFreezeAdmin(admin.ModelAdmin):
list_display = (
'id',
'product',
'warehouse',
'quantity',
'reason',
'created_at',
)
readonly_fields = (
'frozen_by',
'created_at',
'updated_at',
'cancelled_at',
'cancelled_by',
'completed_at',
'completed_by',
'completed_with',
)
search_fields = ('product__name', 'warehouse__name', 'reason')
list_filter = ('warehouse', 'created_at')
ordering = ('-created_at',)