forked from erp-dev/erp
feat: shipment_delivery
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from django.contrib import admin
|
||||
from .models import ExternalFinishedProduct, Shipment, SalesItem
|
||||
from .models import ExternalFinishedProduct, Shipment, SalesItem, ShipmentDelivery
|
||||
|
||||
|
||||
class SalesItemInline(admin.TabularInline):
|
||||
@@ -18,10 +18,29 @@ class ExternalFinishedProductInline(admin.TabularInline):
|
||||
|
||||
@admin.register(Shipment)
|
||||
class ShipmentAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'merchant', 'customer', 'shipment_date', 'status', 'external_id', 'items_count', 'created_by', 'created_at']
|
||||
list_display = [
|
||||
'id',
|
||||
'merchant',
|
||||
'customer',
|
||||
'shipment_date',
|
||||
'status',
|
||||
'delivery',
|
||||
'external_id',
|
||||
'items_count',
|
||||
'created_by',
|
||||
'created_at',
|
||||
]
|
||||
list_filter = ['merchant', 'status', 'shipment_date', 'created_at']
|
||||
search_fields = ['customer__name', 'remark', 'external_id']
|
||||
search_fields = [
|
||||
'customer__name',
|
||||
'remark',
|
||||
'external_id',
|
||||
'address',
|
||||
'contact_name',
|
||||
'contact_phone',
|
||||
]
|
||||
readonly_fields = ['created_at', 'updated_at', 'created_by']
|
||||
raw_id_fields = ['delivery']
|
||||
date_hierarchy = 'shipment_date'
|
||||
inlines = [SalesItemInline, ExternalFinishedProductInline]
|
||||
|
||||
@@ -75,3 +94,77 @@ class ExternalFinishedProductAdmin(admin.ModelAdmin):
|
||||
if not change:
|
||||
obj.created_by = request.user
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
|
||||
@admin.register(ShipmentDelivery)
|
||||
class ShipmentDeliveryAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
'id',
|
||||
'merchant',
|
||||
'driver_name',
|
||||
'vehicle_trip',
|
||||
'contact_phone',
|
||||
'vehicle_capacity',
|
||||
'status',
|
||||
'shipments_count',
|
||||
'operator',
|
||||
'cancelled_by',
|
||||
'created_by',
|
||||
'started_at',
|
||||
'delivered_at',
|
||||
'cancelled_at',
|
||||
'created_at',
|
||||
]
|
||||
list_filter = ['merchant', 'status', 'created_at', 'started_at', 'delivered_at', 'cancelled_at']
|
||||
search_fields = [
|
||||
'driver_name',
|
||||
'vehicle_trip',
|
||||
'contact_phone',
|
||||
'vehicle_capacity',
|
||||
'remark',
|
||||
'internal_remark',
|
||||
'operator__name',
|
||||
'cancelled_by__username',
|
||||
'created_by__username',
|
||||
]
|
||||
readonly_fields = ['created_at', 'updated_at', 'created_by', 'operator', 'cancelled_by', 'cancelled_at', 'shipments_summary']
|
||||
fields = [
|
||||
'merchant',
|
||||
'driver_name',
|
||||
'vehicle_trip',
|
||||
'contact_phone',
|
||||
'vehicle_capacity',
|
||||
'remark',
|
||||
'internal_remark',
|
||||
'status',
|
||||
'started_at',
|
||||
'delivered_at',
|
||||
'cancelled_at',
|
||||
'operator',
|
||||
'cancelled_by',
|
||||
'created_by',
|
||||
'shipments_summary',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]
|
||||
|
||||
def shipments_count(self, obj):
|
||||
return obj.shipments.count()
|
||||
|
||||
shipments_count.short_description = '出货单数量'
|
||||
|
||||
def shipments_summary(self, obj):
|
||||
ids = list(obj.shipments.order_by('id').values_list('id', flat=True))
|
||||
if not ids:
|
||||
return '无'
|
||||
return ', '.join(str(item_id) for item_id in ids)
|
||||
|
||||
shipments_summary.short_description = '关联出货单'
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
if not change:
|
||||
obj.created_by = request.user
|
||||
employee = getattr(request.user, 'employee', None)
|
||||
if employee:
|
||||
obj.operator = employee
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
Reference in New Issue
Block a user