bornhack-website/src/economy/admin.py

113 lines
2.5 KiB
Python
Raw Normal View History

from django.contrib import admin
from .models import Chain, Credebtor, Expense, Reimbursement, Revenue
### chains and credebtors
2019-06-16 12:32:24 +00:00
@admin.register(Chain)
class ChainAdmin(admin.ModelAdmin):
2019-06-16 12:32:24 +00:00
list_filter = ["name"]
list_display = ["name", "notes"]
search_fields = ["name", "notes"]
@admin.register(Credebtor)
class ChainAdmin(admin.ModelAdmin):
2019-06-16 12:32:24 +00:00
list_filter = ["chain", "name"]
list_display = ["chain", "name", "notes"]
search_fields = ["chain", "name", "notes"]
### expenses
2019-06-16 12:32:24 +00:00
def approve_expenses(modeladmin, request, queryset):
for expense in queryset.all():
expense.approve(request)
2019-06-16 12:32:24 +00:00
approve_expenses.short_description = "Approve Expenses"
def reject_expenses(modeladmin, request, queryset):
for expense in queryset.all():
expense.reject(request)
2019-06-16 12:32:24 +00:00
reject_expenses.short_description = "Reject Expenses"
@admin.register(Expense)
class ExpenseAdmin(admin.ModelAdmin):
2019-06-16 12:32:24 +00:00
list_filter = [
"camp",
"creditor__chain",
"creditor",
"responsible_team",
"approved",
"user",
]
list_display = [
"user",
"description",
"invoice_date",
"amount",
"camp",
"creditor",
"responsible_team",
"approved",
"reimbursement",
]
search_fields = ["description", "amount", "uuid"]
actions = [approve_expenses, reject_expenses]
2018-08-30 11:17:34 +00:00
### revenues
2019-06-16 12:32:24 +00:00
def approve_revenues(modeladmin, request, queryset):
for revenue in queryset.all():
revenue.approve(request)
2019-06-16 12:32:24 +00:00
approve_revenues.short_description = "Approve Revenues"
def reject_revenues(modeladmin, request, queryset):
for revenue in queryset.all():
revenue.reject(request)
2019-06-16 12:32:24 +00:00
reject_revenues.short_description = "Reject Revenues"
@admin.register(Revenue)
class RevenueAdmin(admin.ModelAdmin):
2019-06-16 12:32:24 +00:00
list_filter = ["camp", "responsible_team", "approved", "user"]
list_display = [
"user",
"description",
"invoice_date",
"amount",
"camp",
"responsible_team",
"approved",
]
search_fields = ["description", "amount", "user"]
actions = [approve_revenues, reject_revenues]
### reimbursements
2019-06-16 12:32:24 +00:00
2018-08-30 11:17:34 +00:00
@admin.register(Reimbursement)
class ReimbursementAdmin(admin.ModelAdmin):
def get_amount(self, obj):
return obj.amount
2019-06-16 12:32:24 +00:00
list_filter = ["camp", "user", "reimbursement_user", "paid"]
list_display = ["camp", "user", "reimbursement_user", "paid", "notes", "get_amount"]
search_fields = ["user__username", "reimbursement_user__username", "notes"]