|
|
|
@ -1,6 +1,8 @@
@@ -1,6 +1,8 @@
|
|
|
|
|
from django.contrib import admin |
|
|
|
|
from cash.models import * |
|
|
|
|
from django import forms |
|
|
|
|
from django.template.defaultfilters import escape |
|
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
|
|
|
|
|
|
class AccountForm(forms.ModelForm): |
|
|
|
|
credit_change = forms.DecimalField(max_digits = 5, decimal_places = 2, required = False) |
|
|
|
@ -9,10 +11,15 @@ class AccountForm(forms.ModelForm):
@@ -9,10 +11,15 @@ class AccountForm(forms.ModelForm):
|
|
|
|
|
model = Account |
|
|
|
|
|
|
|
|
|
class AccountAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ('user', 'card_number', 'credit') |
|
|
|
|
list_display = ('user', 'card_number', 'credit', 'transaction_link') |
|
|
|
|
form = AccountForm |
|
|
|
|
readonly_fields = ('credit',) |
|
|
|
|
|
|
|
|
|
def transaction_link(self, account): |
|
|
|
|
return '<a href="%s?account__id__exact=%d">Transaktionen</a>' % (reverse("admin:cash_transaction_changelist"), account.id) |
|
|
|
|
|
|
|
|
|
transaction_link.allow_tags = True |
|
|
|
|
|
|
|
|
|
def save_model(self, request, obj, form, change): |
|
|
|
|
# TODO: Auslagern |
|
|
|
|
PAYOUT_SUBJECT = "Auszahlung" |
|
|
|
@ -41,20 +48,39 @@ class ProductAdmin(admin.ModelAdmin):
@@ -41,20 +48,39 @@ class ProductAdmin(admin.ModelAdmin):
|
|
|
|
|
list_filter = ['category'] |
|
|
|
|
inlines= [ProductBarcodeInline] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductCategoryAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ('name', 'comment') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SalesLogEntryAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ('account', 'timestamp', 'product', 'count', 'unit_price') |
|
|
|
|
list_filter = ['account', 'timestamp', 'product'] |
|
|
|
|
|
|
|
|
|
class TransactionAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ('account', 'timestamp', 'subject', 'description', 'amount') |
|
|
|
|
list_filter = ['account', 'timestamp', 'subject'] |
|
|
|
|
actions = None |
|
|
|
|
date_hierarchy = 'timestamp' |
|
|
|
|
|
|
|
|
|
# Disable tampering with the transactions completely |
|
|
|
|
def has_add_permission(self, request): |
|
|
|
|
return False |
|
|
|
|
def has_change_permission(self, request, obj=None): |
|
|
|
|
if obj is None: |
|
|
|
|
return True |
|
|
|
|
return False |
|
|
|
|
def has_delete_permission(self, request, obj=None): |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
# Needed to not trigger an ImproperlyConfigured exception |
|
|
|
|
# FIXME: a bit too hacky |
|
|
|
|
def changelist_view(self, request, extra_context=None): |
|
|
|
|
self.list_display_links = (None, ) |
|
|
|
|
return super(TransactionAdmin, self).changelist_view(request, extra_context=None) |
|
|
|
|
|
|
|
|
|
admin.site.register(Account, AccountAdmin) |
|
|
|
|
admin.site.register(Product, ProductAdmin) |
|
|
|
|
admin.site.register(ProductBarcode) |
|
|
|
|
admin.site.register(ProductCategory, ProductCategoryAdmin) |
|
|
|
|
admin.site.register(Transaction) |
|
|
|
|
admin.site.register(Transaction, TransactionAdmin) |
|
|
|
|
admin.site.register(SalesLogEntry, SalesLogEntryAdmin) |
|
|
|
|
|
|
|
|
|