mpeltriaux
fb8b338950
* adds more log details on adding/removing documents * fixes bug in admin backend where restoring of non-compensation entries led to an error * fixes bug where deleting of revocation without an attached file would lead to an error
139 lines
3.4 KiB
Python
139 lines
3.4 KiB
Python
from django.contrib import admin
|
|
|
|
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
|
EcoAccountDeduction, EcoAccount
|
|
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
|
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
|
from user.models import UserAction
|
|
|
|
|
|
class AbstractCompensationAdmin(BaseObjectAdmin):
|
|
list_display = [
|
|
"id",
|
|
"identifier",
|
|
"title",
|
|
"created",
|
|
"deleted",
|
|
]
|
|
|
|
def get_fields(self, request, obj=None):
|
|
return super().get_fields(request, obj) + [
|
|
"identifier",
|
|
"title",
|
|
"comment",
|
|
"after_states",
|
|
"before_states",
|
|
]
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
return super().get_readonly_fields(request, obj) + [
|
|
"after_states",
|
|
"before_states",
|
|
]
|
|
|
|
|
|
class CompensationAdmin(AbstractCompensationAdmin):
|
|
autocomplete_fields = [
|
|
"intervention",
|
|
]
|
|
|
|
def get_fields(self, request, obj=None):
|
|
return super().get_fields(request, obj) + [
|
|
"is_cef",
|
|
"is_coherence_keeping",
|
|
"intervention",
|
|
]
|
|
|
|
def restore_deleted_data(self, request, queryset):
|
|
super().restore_deleted_data(request, queryset)
|
|
|
|
for entry in queryset:
|
|
# Remove delete log entry from related intervention log history
|
|
logs = entry.intervention.log.filter(
|
|
action=UserAction.EDITED,
|
|
comment=COMPENSATION_REMOVED_TEMPLATE.format(entry.identifier)
|
|
)
|
|
logs.delete()
|
|
|
|
|
|
class EcoAccountAdmin(AbstractCompensationAdmin):
|
|
list_display = [
|
|
"id",
|
|
"identifier",
|
|
"title",
|
|
"created",
|
|
"deleted",
|
|
]
|
|
|
|
filter_horizontal = [
|
|
"users"
|
|
]
|
|
|
|
def get_fields(self, request, obj=None):
|
|
return super().get_fields(request, obj) + [
|
|
"deductable_surface",
|
|
"users"
|
|
]
|
|
|
|
|
|
class PaymentAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"amount",
|
|
"due_on",
|
|
]
|
|
|
|
|
|
class EcoAccountDeductionAdmin(BaseResourceAdmin):
|
|
list_display = [
|
|
"id",
|
|
"account",
|
|
"intervention",
|
|
"surface",
|
|
]
|
|
search_fields = [
|
|
"account__identifier",
|
|
"account__title",
|
|
"intervention__identifier",
|
|
"intervention__title",
|
|
"surface",
|
|
]
|
|
autocomplete_fields = [
|
|
"account",
|
|
"intervention",
|
|
]
|
|
|
|
def get_fields(self, request, obj=None):
|
|
return super().get_fields(request, obj) + [
|
|
"account",
|
|
"intervention",
|
|
"surface",
|
|
]
|
|
|
|
|
|
class CompensationStateAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"biotope_type",
|
|
"surface",
|
|
]
|
|
|
|
|
|
class CompensationActionAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"action_type",
|
|
"amount",
|
|
"unit",
|
|
"comment",
|
|
]
|
|
|
|
|
|
admin.site.register(Compensation, CompensationAdmin)
|
|
admin.site.register(EcoAccount, EcoAccountAdmin)
|
|
admin.site.register(EcoAccountDeduction, EcoAccountDeductionAdmin)
|
|
|
|
# For a more cleaner admin interface these rarely used admin views are not important for deployment
|
|
#admin.site.register(Payment, PaymentAdmin)
|
|
#admin.site.register(CompensationAction, CompensationActionAdmin)
|
|
#admin.site.register(CompensationState, CompensationStateAdmin) |