from django.contrib import admin 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"] @admin.register(Customer) class CustomerAdmin(admin.ModelAdmin): 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", ) @admin.register(LedgerEntry) class LedgerEntryAdmin(admin.ModelAdmin): list_display = ("title", "entry_type", "category", "amount", "entry_date", "counterparty_name") list_filter = ("entry_type", "category") 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") @admin.register(Product) class ProductAdmin(admin.ModelAdmin): list_display = ("name", "sku", "category", "quantity", "unit", "unit_price", "total_purchase_value") list_filter = ("category",) search_fields = ("name", "sku", "user__phone") readonly_fields = ("total_purchase_value",) @admin.register(StockMovement) class StockMovementAdmin(admin.ModelAdmin): list_display = ("product", "delta", "quantity_after", "note", "created_at") search_fields = ("product__name",) class InvoiceItemInline(admin.TabularInline): model = InvoiceItem extra = 0 @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] @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")