Files

83 lines
2.7 KiB
Python
Raw Permalink Normal View History

2026-08-24 15:54:08 +03:30
from django.contrib import admin
2026-09-04 13:05:54 +03:30
from .models import (
Account,
Customer,
Invoice,
InvoiceItem,
LedgerEntry,
LedgerInstallment,
Product,
StockMovement,
Transaction,
)
@admin.register(Account)
class AccountAdmin(admin.ModelAdmin):
list_display = ("code", "name", "level", "account_type", "parent", "is_system", "is_active")
list_filter = ("level", "account_type", "is_system", "is_active")
search_fields = ("code", "name", "user__phone")
autocomplete_fields = ["parent"]
2026-08-24 15:54:08 +03:30
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
2026-09-04 13:05:54 +03:30
list_display = ("name", "phone", "outstanding_balance", "total_purchases_count", "last_purchase_date")
search_fields = ("name", "phone", "user__phone")
readonly_fields = (
"total_purchases_count", "total_purchase_amount", "last_purchase_date", "outstanding_balance",
)
2026-08-24 15:54:08 +03:30
@admin.register(LedgerEntry)
class LedgerEntryAdmin(admin.ModelAdmin):
2026-09-04 13:05:54 +03:30
list_display = ("title", "entry_type", "category", "amount", "entry_date", "counterparty_name")
2026-08-24 15:54:08 +03:30
list_filter = ("entry_type", "category")
2026-09-04 13:05:54 +03:30
search_fields = ("title", "counterparty_name", "counterparty_phone", "user__phone")
@admin.register(LedgerInstallment)
class LedgerInstallmentAdmin(admin.ModelAdmin):
list_display = ("ledger_entry", "amount", "paid_date", "reference")
search_fields = ("reference", "ledger_entry__title")
2026-08-24 15:54:08 +03:30
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
2026-09-04 13:05:54 +03:30
list_display = ("name", "sku", "category", "quantity", "unit", "unit_price", "total_purchase_value")
2026-08-24 15:54:08 +03:30
list_filter = ("category",)
search_fields = ("name", "sku", "user__phone")
2026-09-04 13:05:54 +03:30
readonly_fields = ("total_purchase_value",)
2026-08-24 15:54:08 +03:30
@admin.register(StockMovement)
class StockMovementAdmin(admin.ModelAdmin):
2026-09-04 13:05:54 +03:30
list_display = ("product", "delta", "quantity_after", "note", "created_at")
search_fields = ("product__name",)
class InvoiceItemInline(admin.TabularInline):
model = InvoiceItem
extra = 0
2026-08-24 15:54:08 +03:30
2026-09-04 13:05:54 +03:30
@admin.register(Invoice)
class InvoiceAdmin(admin.ModelAdmin):
list_display = (
"invoice_number", "buyer_name", "final_amount", "payment_type", "payment_status", "order_status",
"invoice_date",
)
list_filter = ("payment_type", "payment_status", "order_status")
search_fields = ("invoice_number", "buyer_name", "buyer_phone", "user__phone")
inlines = [InvoiceItemInline]
2026-08-24 15:54:08 +03:30
2026-09-04 13:05:54 +03:30
@admin.register(Transaction)
class TransactionAdmin(admin.ModelAdmin):
list_display = (
"transaction_number", "transaction_type", "debit_account", "credit_account", "amount", "transaction_date",
)
list_filter = ("transaction_type",)
search_fields = ("transaction_number", "description", "user__phone")