85 lines
3.5 KiB
Python
85 lines
3.5 KiB
Python
from django.contrib import admin
|
|
from .models import ManufacturingOrder, ManufacturingLine, ManufacturingOrderLine, BillOfMaterials, BillOfMaterialsTotal
|
|
|
|
@admin.register(ManufacturingOrder)
|
|
class ManufacturingOrderAdmin(admin.ModelAdmin):
|
|
list_display = ('order_number', 'product', 'quantity', 'date', 'status',
|
|
'total_cost', 'created_by', 'created_at')
|
|
list_filter = ('status', 'date', 'product__category', 'created_by', 'created_at')
|
|
search_fields = ('order_number', 'product__name', 'product__code', 'notes')
|
|
ordering = ('-date', '-created_at')
|
|
|
|
fieldsets = (
|
|
('Order Information', {'fields': ('order_number', 'date', 'product', 'quantity', 'status')}),
|
|
('Cost Information', {'fields': ('labor_cost', 'overhead_cost', 'total_cost')}),
|
|
('Additional Information', {'fields': ('notes', 'created_by')}),
|
|
)
|
|
|
|
readonly_fields = ('total_cost',)
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related('product', 'created_by')
|
|
|
|
|
|
@admin.register(ManufacturingLine)
|
|
class ManufacturingLineAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'capacity_per_hour', 'is_active', 'created_at')
|
|
list_filter = ('is_active', 'created_at')
|
|
search_fields = ('name', 'description')
|
|
ordering = ('name',)
|
|
|
|
fieldsets = (
|
|
(None, {'fields': ('name', 'description', 'capacity_per_hour')}),
|
|
('Status', {'fields': ('is_active',)}),
|
|
)
|
|
|
|
|
|
@admin.register(ManufacturingOrderLine)
|
|
class ManufacturingOrderLineAdmin(admin.ModelAdmin):
|
|
list_display = ('manufacturing_order', 'manufacturing_line', 'actual_quantity',
|
|
'start_time', 'end_time')
|
|
list_filter = ('manufacturing_line', 'start_time', 'end_time')
|
|
search_fields = ('manufacturing_order__order_number', 'notes')
|
|
ordering = ('-start_time',)
|
|
|
|
fieldsets = (
|
|
('Line Information', {'fields': ('manufacturing_order', 'manufacturing_line')}),
|
|
('Timing', {'fields': ('start_time', 'end_time')}),
|
|
('Production', {'fields': ('actual_quantity', 'notes')}),
|
|
)
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related('manufacturing_order', 'manufacturing_line')
|
|
|
|
|
|
@admin.register(BillOfMaterials)
|
|
class BillOfMaterialsAdmin(admin.ModelAdmin):
|
|
list_display = ('manufactured_product', 'component', 'quantity', 'unit', 'created_at')
|
|
list_filter = ('manufactured_product__category', 'created_at')
|
|
search_fields = ('manufactured_product__name', 'manufactured_product__code',
|
|
'component__name', 'component__code')
|
|
ordering = ('manufactured_product__name', 'component__name')
|
|
|
|
fieldsets = (
|
|
('BOM Information', {'fields': ('manufactured_product', 'component', 'quantity', 'unit')}),
|
|
)
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related('manufactured_product', 'component')
|
|
|
|
|
|
@admin.register(BillOfMaterialsTotal)
|
|
class BillOfMaterialsTotalAdmin(admin.ModelAdmin):
|
|
list_display = ('bom', 'total_cost', 'total_weight', 'last_calculated')
|
|
list_filter = ('last_calculated',)
|
|
search_fields = ('bom__manufactured_product__name', 'bom__component__name')
|
|
ordering = ('-last_calculated',)
|
|
|
|
fieldsets = (
|
|
('BOM Total Information', {'fields': ('bom', 'total_cost', 'total_weight')}),
|
|
)
|
|
readonly_fields = ('last_calculated',)
|
|
|
|
def get_queryset(self, request):
|
|
return super().get_queryset(request).select_related('bom__manufactured_product', 'bom__component')
|