2021-07-01 13:36:07 +02:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2021-08-04 11:56:56 +02:00
|
|
|
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
2021-08-30 11:34:35 +02:00
|
|
|
EcoAccountDeduction, EcoAccount
|
2022-02-01 18:41:02 +01:00
|
|
|
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
2022-02-04 09:18:46 +01:00
|
|
|
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
|
|
|
from user.models import UserAction
|
2021-07-01 13:36:07 +02:00
|
|
|
|
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
class AbstractCompensationAdmin(BaseObjectAdmin):
|
2021-07-01 13:36:07 +02:00
|
|
|
list_display = [
|
|
|
|
"id",
|
2022-02-01 18:41:02 +01:00
|
|
|
"identifier",
|
|
|
|
"title",
|
|
|
|
"created",
|
|
|
|
"deleted",
|
2021-07-01 13:36:07 +02:00
|
|
|
]
|
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
def get_fields(self, request, obj=None):
|
|
|
|
return super().get_fields(request, obj) + [
|
|
|
|
"identifier",
|
|
|
|
"title",
|
|
|
|
"comment",
|
|
|
|
"after_states",
|
|
|
|
"before_states",
|
|
|
|
]
|
2021-07-01 13:36:07 +02:00
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
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",
|
2021-07-01 13:36:07 +02:00
|
|
|
]
|
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
def get_fields(self, request, obj=None):
|
|
|
|
return super().get_fields(request, obj) + [
|
|
|
|
"is_cef",
|
|
|
|
"is_coherence_keeping",
|
|
|
|
"intervention",
|
|
|
|
]
|
|
|
|
|
2022-02-04 09:18:46 +01:00
|
|
|
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()
|
|
|
|
|
2021-07-01 13:36:07 +02:00
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
class EcoAccountAdmin(AbstractCompensationAdmin):
|
2021-07-01 13:36:07 +02:00
|
|
|
list_display = [
|
|
|
|
"id",
|
2021-08-02 10:14:34 +02:00
|
|
|
"identifier",
|
|
|
|
"title",
|
2021-08-02 11:52:20 +02:00
|
|
|
"created",
|
2022-01-24 14:41:56 +01:00
|
|
|
"deleted",
|
2021-07-01 13:36:07 +02:00
|
|
|
]
|
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
filter_horizontal = [
|
|
|
|
"users"
|
2021-08-02 10:14:34 +02:00
|
|
|
]
|
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
def get_fields(self, request, obj=None):
|
|
|
|
return super().get_fields(request, obj) + [
|
|
|
|
"deductable_surface",
|
|
|
|
"users"
|
|
|
|
]
|
|
|
|
|
2021-08-02 10:14:34 +02:00
|
|
|
|
2021-07-21 14:17:18 +02:00
|
|
|
class PaymentAdmin(admin.ModelAdmin):
|
|
|
|
list_display = [
|
|
|
|
"id",
|
|
|
|
"amount",
|
2021-07-26 11:29:05 +02:00
|
|
|
"due_on",
|
2021-07-21 14:17:18 +02:00
|
|
|
]
|
|
|
|
|
2021-07-01 13:36:07 +02:00
|
|
|
|
2022-02-01 18:41:02 +01:00
|
|
|
class EcoAccountDeductionAdmin(BaseResourceAdmin):
|
2021-08-02 10:14:34 +02:00
|
|
|
list_display = [
|
|
|
|
"id",
|
|
|
|
"account",
|
|
|
|
"intervention",
|
2021-08-09 14:16:54 +02:00
|
|
|
"surface",
|
2021-08-02 10:14:34 +02:00
|
|
|
]
|
2022-02-01 18:41:02 +01:00
|
|
|
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",
|
|
|
|
]
|
2021-08-02 10:14:34 +02:00
|
|
|
|
|
|
|
|
2021-07-01 13:36:07 +02:00
|
|
|
admin.site.register(Compensation, CompensationAdmin)
|
2021-08-02 10:14:34 +02:00
|
|
|
admin.site.register(EcoAccount, EcoAccountAdmin)
|
2021-08-30 11:34:35 +02:00
|
|
|
admin.site.register(EcoAccountDeduction, EcoAccountDeductionAdmin)
|
2022-02-01 18:41:02 +01:00
|
|
|
|
|
|
|
# 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)
|