2018-08-29 22:52:32 +00:00
|
|
|
from django.contrib import admin
|
2019-03-28 06:04:53 +00:00
|
|
|
|
|
|
|
from .models import Chain, Credebtor, Expense, Reimbursement, Revenue
|
|
|
|
|
|
|
|
|
|
|
|
### chains and credebtors
|
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
|
2019-03-28 06:04:53 +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"]
|
2019-03-28 06:04:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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"]
|
2018-08-29 22:52:32 +00:00
|
|
|
|
|
|
|
|
2018-11-20 16:12:32 +00:00
|
|
|
### expenses
|
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
|
2018-08-29 22:52:32 +00:00
|
|
|
def approve_expenses(modeladmin, request, queryset):
|
|
|
|
for expense in queryset.all():
|
2018-08-29 23:35:37 +00:00
|
|
|
expense.approve(request)
|
2019-06-16 12:32:24 +00:00
|
|
|
|
|
|
|
|
2018-08-29 22:52:32 +00:00
|
|
|
approve_expenses.short_description = "Approve Expenses"
|
|
|
|
|
|
|
|
|
|
|
|
def reject_expenses(modeladmin, request, queryset):
|
|
|
|
for expense in queryset.all():
|
2018-08-29 23:35:37 +00:00
|
|
|
expense.reject(request)
|
2019-06-16 12:32:24 +00:00
|
|
|
|
|
|
|
|
2018-08-29 22:52:32 +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"]
|
2018-08-29 22:52:32 +00:00
|
|
|
actions = [approve_expenses, reject_expenses]
|
|
|
|
|
2018-08-30 11:17:34 +00:00
|
|
|
|
2018-11-20 16:12:32 +00:00
|
|
|
### revenues
|
|
|
|
|
2019-06-16 12:32:24 +00:00
|
|
|
|
2018-11-20 16:12:32 +00:00
|
|
|
def approve_revenues(modeladmin, request, queryset):
|
|
|
|
for revenue in queryset.all():
|
|
|
|
revenue.approve(request)
|
2019-06-16 12:32:24 +00:00
|
|
|
|
|
|
|
|
2018-11-20 16:12:32 +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
|
|
|
|
|
|
|
|
2018-11-20 16:12:32 +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"]
|
2018-11-20 16:12:32 +00:00
|
|
|
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"]
|