2024-07-15 00:19:37 +02:00
|
|
|
"""Admin for the accounting app."""
|
|
|
|
|
2018-06-23 21:08:56 +02:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2024-07-15 00:19:37 +02:00
|
|
|
from .models import Order
|
|
|
|
from .models import Payment
|
2018-06-23 21:08:56 +02:00
|
|
|
|
|
|
|
|
2024-07-15 00:19:37 +02:00
|
|
|
@admin.register(Order)
|
2018-06-23 21:08:56 +02:00
|
|
|
class OrderAdmin(admin.ModelAdmin):
|
2024-07-15 00:19:37 +02:00
|
|
|
"""Admin for the Order model."""
|
|
|
|
|
2019-09-01 00:27:36 +02:00
|
|
|
list_display = ("who", "description", "created", "is_paid")
|
2018-06-23 21:08:56 +02:00
|
|
|
|
2023-01-03 21:39:40 +01:00
|
|
|
@admin.display(description=_("Customer"))
|
2024-07-15 00:19:37 +02:00
|
|
|
def who(self, instance: Order) -> str:
|
|
|
|
"""Return the full name of the user who made the order."""
|
2018-06-23 21:08:56 +02:00
|
|
|
return instance.user.get_full_name()
|
2019-09-01 00:27:36 +02:00
|
|
|
|
2018-06-23 21:08:56 +02:00
|
|
|
|
2024-07-15 00:19:37 +02:00
|
|
|
@admin.register(Payment)
|
2018-06-23 21:08:56 +02:00
|
|
|
class PaymentAdmin(admin.ModelAdmin):
|
2024-07-15 00:19:37 +02:00
|
|
|
"""Admin for the Payment model."""
|
|
|
|
|
2019-09-01 00:27:36 +02:00
|
|
|
list_display = ("who", "description", "order_id", "created")
|
2018-06-23 21:08:56 +02:00
|
|
|
|
2023-01-03 21:39:40 +01:00
|
|
|
@admin.display(description=_("Customer"))
|
2024-07-15 00:19:37 +02:00
|
|
|
def who(self, instance: Payment) -> str:
|
|
|
|
"""Return the full name of the user who made the payment."""
|
2018-06-23 21:08:56 +02:00
|
|
|
return instance.order.user.get_full_name()
|
2019-09-01 00:27:36 +02:00
|
|
|
|
2023-01-03 21:39:40 +01:00
|
|
|
@admin.display(description=_("Order ID"))
|
2024-07-15 00:19:37 +02:00
|
|
|
def order_id(self, instance: Payment) -> int:
|
|
|
|
"""Return the ID of the order."""
|
2018-06-23 21:08:56 +02:00
|
|
|
return instance.order.id
|