forked from erp-dev/erp
76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
from django.contrib import admin
|
|
|
|
from . import models
|
|
|
|
|
|
@admin.register(models.PurchaseOrder)
|
|
class PurchaseOrderAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'supplier', 'purchase_date', 'operator', 'status', '_total_amount', '_diff_quantity', '_total_quantity', 'created_at')
|
|
search_fields = ('supplier__name',)
|
|
list_filter = ('operator', 'warehouse', 'status', 'created_at')
|
|
ordering = ('-created_at',)
|
|
|
|
@admin.display(description='总价')
|
|
def _total_amount(self, obj: models.PurchaseOrder):
|
|
return obj.get_total_amount()
|
|
|
|
@admin.display(description='差异数量')
|
|
def _diff_quantity(self, obj: models.PurchaseOrder):
|
|
return obj.get_total_diff_quantity()
|
|
|
|
@admin.display(description='总数量')
|
|
def _total_quantity(self, obj: models.PurchaseOrder):
|
|
return obj.get_total_quantity()
|
|
|
|
|
|
@admin.register(models.PurchaseOrderItem)
|
|
class PurchaseOrderItemAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
'id', 'purchase_order', 'product',
|
|
'quantity', 'unit', 'price', 'batch_number',
|
|
'_total_amount', 'empty_diff_percent',
|
|
'_real_quantity', '_diff_quantity',
|
|
'num_of_rolls',
|
|
)
|
|
search_fields = ('purchase_order__id', 'product__name')
|
|
list_filter = ('purchase_order__operator', 'purchase_order__warehouse', 'created_at')
|
|
ordering = ('-created_at',)
|
|
|
|
@admin.display(description='实际数量')
|
|
def _real_quantity(self, obj: models.PurchaseOrderItem):
|
|
return obj.real_quantity()
|
|
|
|
@admin.display(description='差异数量')
|
|
def _diff_quantity(self, obj: models.PurchaseOrderItem):
|
|
return obj.diff_quantity()
|
|
|
|
@admin.display(description='总金额')
|
|
def _total_amount(self, obj: models.PurchaseOrderItem):
|
|
return obj.total_amount()
|
|
|
|
|
|
@admin.register(models.CustomerBalance)
|
|
class CustomerBalancemAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'customer', 'balance', 'created_at')
|
|
search_fields = ('customer_balance__id', 'product__name')
|
|
ordering = ('-created_at',)
|
|
|
|
|
|
@admin.register(models.BalanceChangeRecord)
|
|
class BalanceChangeRecordAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'merchant', 'target_type', 'source_type', 'source_id', 'delta', 'balance_before', 'balance_after', 'direction', 'created_at')
|
|
search_fields = ('merchant__name', 'target_type', 'source_type', 'source_id')
|
|
list_filter = ('merchant', 'target_type', 'source_type', 'direction', 'created_at')
|
|
ordering = ('-created_at',)
|
|
|
|
@admin.display(description='商户')
|
|
def merchant(self, obj: models.BalanceChangeRecord):
|
|
return obj.merchant.name
|
|
|
|
@admin.display(description='目标类型')
|
|
def target_type(self, obj: models.BalanceChangeRecord):
|
|
return obj.target_type.label
|
|
|
|
@admin.display(description='来源类型')
|
|
def source_type(self, obj: models.BalanceChangeRecord):
|
|
return obj.source_type.label |