150 lines
5.4 KiB
Python
150 lines
5.4 KiB
Python
from django.contrib.gis import admin
|
|
from django.utils.html import format_html
|
|
|
|
from .models import (
|
|
Product, ProductCategory, Warehouse, WarehouseLocation, Stock, StockMovement,
|
|
PurchaseOrder, PurchaseOrderItem, PreparationOrder, PreparationOrderItem,
|
|
ProductionOrder,
|
|
SerializedItem, SerializedItemEvent,
|
|
)
|
|
|
|
class CustomGeoAdmin(admin.GISModelAdmin):
|
|
gis_widget_kwargs = {
|
|
'attrs': {
|
|
"default_lon" : 4.3517, # Bruxelles (par exemple)
|
|
"default_lat" : 50.8503,
|
|
"default_zoom" : 12
|
|
},
|
|
}
|
|
|
|
|
|
|
|
@admin.register(Warehouse)
|
|
class WarehouseAdmin(CustomGeoAdmin):
|
|
list_display = ('name', 'location', 'manager')
|
|
search_fields = ('name', 'location', 'manager')
|
|
|
|
@admin.register(WarehouseLocation)
|
|
class WarehouseLocationAdmin(CustomGeoAdmin):
|
|
list_display = ('name', 'warehouse', 'is_default')
|
|
list_filter = ('warehouse',)
|
|
search_fields = ('name', 'warehouse__name')
|
|
|
|
@admin.register(ProductCategory)
|
|
class ProductCategoryAdmin(admin.ModelAdmin):
|
|
list_display = ('name_fr', 'name_en', 'name_nl')
|
|
search_fields = ('name_fr', 'name_en', 'name_nl')
|
|
|
|
@admin.register(Product)
|
|
class ProductAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'code', 'category', 'unit', 'price', 'qr_code_preview')
|
|
search_fields = ('name', 'code', 'category__name_fr')
|
|
list_filter = ('category', 'unit')
|
|
readonly_fields = ('qr_code_preview',)
|
|
|
|
def qr_code_preview(self, obj):
|
|
if obj.qr_code:
|
|
return format_html('<img src="{}" style="height:80px;width:80px;" />', obj.qr_code.url)
|
|
return "—"
|
|
qr_code_preview.short_description = 'QR Code'
|
|
|
|
|
|
@admin.register(Stock)
|
|
class StockAdmin(admin.ModelAdmin):
|
|
list_display = ('product', 'location', 'quantity')
|
|
search_fields = ('product__name', 'location__name')
|
|
list_filter = ('location',)
|
|
|
|
@admin.register(StockMovement)
|
|
class StockMovementAdmin(admin.ModelAdmin):
|
|
list_display = ('product', 'source_location', 'destination_location', 'quantity', 'date', 'reason')
|
|
search_fields = ('product__name', 'source_location__name', 'destination_location__name')
|
|
list_filter = ('date', 'product')
|
|
|
|
|
|
class PurchaseOrderItemInline(admin.TabularInline):
|
|
model = PurchaseOrderItem
|
|
extra = 1
|
|
fields = ('product', 'location', 'num_articles', 'quantity_per_article', 'quantity')
|
|
|
|
@admin.register(PurchaseOrder)
|
|
class PurchaseOrderAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'supplier', 'date_ordered')
|
|
search_fields = ('supplier__name',)
|
|
list_filter = ('date_ordered',)
|
|
inlines = [PurchaseOrderItemInline]
|
|
|
|
@admin.register(PurchaseOrderItem)
|
|
class PurchaseOrderItemAdmin(admin.ModelAdmin):
|
|
list_display = ('purchase_order', 'product', 'quantity')
|
|
search_fields = ('purchase_order__id', 'product__name')
|
|
|
|
|
|
class PreparationOrderItemInline(admin.TabularInline):
|
|
model = PreparationOrderItem
|
|
extra = 1
|
|
|
|
@admin.register(PreparationOrder)
|
|
class PreparationOrderAdmin(admin.ModelAdmin):
|
|
list_display = ('order_number', 'date', 'status', 'priority')
|
|
search_fields = ('order_number',)
|
|
list_filter = ('status', 'date', 'priority')
|
|
inlines = [PreparationOrderItemInline]
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
if obj: # editing an existing object
|
|
return self.readonly_fields + ('priority',)
|
|
return self.readonly_fields
|
|
|
|
@admin.register(PreparationOrderItem)
|
|
class PreparationOrderItemAdmin(admin.ModelAdmin):
|
|
list_display = ('preparation_order', 'product', 'quantity')
|
|
search_fields = ('preparation_order__order_number', 'product__name')
|
|
|
|
|
|
# class ProductDesignComponentInline(admin.TabularInline):
|
|
# model = ProductDesignComponent
|
|
# extra = 1
|
|
#
|
|
# @admin.register(ProductDesign)
|
|
# class ProductDesignAdmin(admin.ModelAdmin):
|
|
# list_display = ('code', 'name', 'category', 'status', 'output_product', 'created_at')
|
|
# search_fields = ('code', 'name', 'output_product__name')
|
|
# list_filter = ('status', 'category')
|
|
# inlines = [ProductDesignComponentInline]
|
|
# raw_id_fields = ('output_product',)
|
|
#
|
|
# @admin.register(ProductDesignComponent)
|
|
# class ProductDesignComponentAdmin(admin.ModelAdmin):
|
|
# list_display = ('product_design', 'product', 'quantity')
|
|
# search_fields = ('product_design__name', 'product__name')
|
|
|
|
@admin.register(ProductionOrder)
|
|
class ProductionOrderAdmin(admin.ModelAdmin):
|
|
list_display = ('code', 'warehouse', 'quantity', 'status', 'output_product', 'created_at')
|
|
search_fields = ('code', 'output_product__name', 'output_product_name')
|
|
list_filter = ('status', 'warehouse')
|
|
raw_id_fields = ('output_product', 'output_location')
|
|
|
|
|
|
class SerializedItemEventInline(admin.TabularInline):
|
|
model = SerializedItemEvent
|
|
extra = 0
|
|
readonly_fields = ('created_at', 'created_by')
|
|
fields = ('event_type', 'date', 'person', 'from_location', 'to_location', 'notes', 'created_by', 'created_at')
|
|
|
|
|
|
@admin.register(SerializedItem)
|
|
class SerializedItemAdmin(admin.ModelAdmin):
|
|
list_display = ('serial_number', 'product', 'status', 'current_holder', 'current_location', 'created_at')
|
|
list_filter = ('status', 'product')
|
|
search_fields = ('serial_number', 'product__name', 'product__code')
|
|
inlines = [SerializedItemEventInline]
|
|
|
|
|
|
@admin.register(SerializedItemEvent)
|
|
class SerializedItemEventAdmin(admin.ModelAdmin):
|
|
list_display = ('item', 'event_type', 'date', 'person', 'created_by')
|
|
list_filter = ('event_type',)
|
|
search_fields = ('item__serial_number', 'item__product__name')
|
|
|