forked from erp-dev/erp
feat: new module: 'shipment', new signal when process was finished
This commit is contained in:
49
shipment/admin.py
Normal file
49
shipment/admin.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from django.contrib import admin
|
||||
from .models import Shipment, SalesItem
|
||||
|
||||
|
||||
class SalesItemInline(admin.TabularInline):
|
||||
model = SalesItem
|
||||
extra = 1
|
||||
fields = ['name', 'quantity', 'unit', 'printing_job_id', 'customer_id', 'created_by']
|
||||
readonly_fields = ['created_by']
|
||||
|
||||
|
||||
@admin.register(Shipment)
|
||||
class ShipmentAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'customer', 'shipment_date', 'items_count', 'created_by', 'created_at']
|
||||
list_filter = ['shipment_date', 'created_at']
|
||||
search_fields = ['customer__name', 'remark']
|
||||
readonly_fields = ['created_at', 'updated_at', 'created_by']
|
||||
date_hierarchy = 'shipment_date'
|
||||
inlines = [SalesItemInline]
|
||||
|
||||
def items_count(self, obj):
|
||||
return obj.items.count()
|
||||
items_count.short_description = '销售品数量'
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
if not change:
|
||||
obj.created_by = request.user
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
def save_formset(self, request, form, formset, change):
|
||||
instances = formset.save(commit=False)
|
||||
for instance in instances:
|
||||
if isinstance(instance, SalesItem) and not instance.pk:
|
||||
instance.created_by = request.user
|
||||
instance.save()
|
||||
formset.save_m2m()
|
||||
|
||||
|
||||
@admin.register(SalesItem)
|
||||
class SalesItemAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'name', 'quantity', 'unit', 'shipment', 'printing_job_id', 'customer_id', 'created_by', 'created_at']
|
||||
list_filter = ['unit', 'created_at']
|
||||
search_fields = ['name', 'shipment__customer__name']
|
||||
readonly_fields = ['created_at', 'updated_at', 'created_by']
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
if not change:
|
||||
obj.created_by = request.user
|
||||
super().save_model(request, obj, form, change)
|
||||
Reference in New Issue
Block a user