mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
enhance admin pages
This commit is contained in:
115
counter/admin.py
115
counter/admin.py
@ -21,19 +21,36 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from ajax_select import make_ajax_form
|
||||
from django.contrib import admin
|
||||
from haystack.admin import SearchModelAdmin
|
||||
|
||||
from counter.models import *
|
||||
|
||||
|
||||
@admin.register(Product)
|
||||
class ProductAdmin(SearchModelAdmin):
|
||||
search_fields = ["name", "code"]
|
||||
list_display = (
|
||||
"name",
|
||||
"code",
|
||||
"product_type",
|
||||
"selling_price",
|
||||
"profit",
|
||||
"archived",
|
||||
)
|
||||
search_fields = ("name", "code")
|
||||
|
||||
|
||||
@admin.register(Customer)
|
||||
class CustomerAdmin(SearchModelAdmin):
|
||||
search_fields = ["account_id"]
|
||||
list_display = ("user", "account_id", "amount")
|
||||
search_fields = (
|
||||
"account_id",
|
||||
"user__username",
|
||||
"user__first_name",
|
||||
"user__last_name",
|
||||
)
|
||||
form = make_ajax_form(Customer, {"user": "users"})
|
||||
|
||||
|
||||
@admin.register(BillingInfo)
|
||||
@ -41,12 +58,86 @@ class BillingInfoAdmin(admin.ModelAdmin):
|
||||
list_display = ("first_name", "last_name", "address_1", "city", "country")
|
||||
|
||||
|
||||
admin.site.register(Customer, CustomerAdmin)
|
||||
admin.site.register(Product, ProductAdmin)
|
||||
admin.site.register(ProductType)
|
||||
admin.site.register(Counter)
|
||||
admin.site.register(Refilling)
|
||||
admin.site.register(Selling)
|
||||
admin.site.register(Permanency)
|
||||
admin.site.register(CashRegisterSummary)
|
||||
admin.site.register(Eticket)
|
||||
@admin.register(Counter)
|
||||
class CounterAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "club", "type")
|
||||
form = make_ajax_form(
|
||||
Counter,
|
||||
{
|
||||
"products": "products",
|
||||
"sellers": "users",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Refilling)
|
||||
class RefillingAdmin(SearchModelAdmin):
|
||||
list_display = ("customer", "amount", "counter", "payment_method", "date")
|
||||
search_fields = (
|
||||
"customer__user__username",
|
||||
"customer__user__first_name",
|
||||
"customer__user__last_name",
|
||||
"customer__account_id",
|
||||
"counter__name",
|
||||
)
|
||||
form = make_ajax_form(
|
||||
Refilling,
|
||||
{
|
||||
"customer": "customers",
|
||||
"operator": "users",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Selling)
|
||||
class SellingAdmin(SearchModelAdmin):
|
||||
list_display = ("customer", "label", "unit_price", "quantity", "counter", "date")
|
||||
search_fields = (
|
||||
"customer__user__username",
|
||||
"customer__user__first_name",
|
||||
"customer__user__last_name",
|
||||
"customer__account_id",
|
||||
"counter__name",
|
||||
)
|
||||
form = make_ajax_form(
|
||||
Selling,
|
||||
{
|
||||
"customer": "customers",
|
||||
"seller": "users",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Permanency)
|
||||
class PermanencyAdmin(SearchModelAdmin):
|
||||
list_display = ("user", "counter", "start", "duration")
|
||||
search_fields = (
|
||||
"user__username",
|
||||
"user__first_name",
|
||||
"user__last_name",
|
||||
"counter__name",
|
||||
)
|
||||
form = make_ajax_form(Permanency, {"user": "users"})
|
||||
|
||||
|
||||
@admin.register(ProductType)
|
||||
class ProductTypeAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "priority")
|
||||
|
||||
|
||||
@admin.register(CashRegisterSummary)
|
||||
class CashRegisterSummaryAdmin(SearchModelAdmin):
|
||||
list_display = ("user", "counter", "date")
|
||||
search_fields = (
|
||||
"user__username",
|
||||
"user__first_name",
|
||||
"user__last_name",
|
||||
"counter__name",
|
||||
)
|
||||
form = make_ajax_form(CashRegisterSummary, {"user": "users"})
|
||||
|
||||
|
||||
@admin.register(Eticket)
|
||||
class EticketAdmin(SearchModelAdmin):
|
||||
list_display = ("product", "event_date", "event_title")
|
||||
search_fields = ("product__name", "event_title")
|
||||
|
@ -305,6 +305,10 @@ class Product(models.Model):
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def profit(self):
|
||||
return self.selling_price - self.purchase_price
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s)" % (self.name, self.code)
|
||||
|
||||
@ -762,6 +766,12 @@ class Permanency(models.Model):
|
||||
self.end.strftime("%Y-%m-%d %H:%M:%S") if self.end else "",
|
||||
)
|
||||
|
||||
@property
|
||||
def duration(self):
|
||||
if self.end is None:
|
||||
return self.activity - self.start
|
||||
return self.end - self.start
|
||||
|
||||
|
||||
class CashRegisterSummary(models.Model):
|
||||
user = models.ForeignKey(
|
||||
|
Reference in New Issue
Block a user