Frederic
11 years ago
2 changed files with 69 additions and 14 deletions
@ -1,35 +1,86 @@ |
|||||||
from django.contrib import admin |
from django.contrib import admin |
||||||
from cash.models import * |
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) |
||||||
|
|
||||||
|
class Meta: |
||||||
|
model = Account |
||||||
|
|
||||||
class AccountAdmin(admin.ModelAdmin): |
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" |
||||||
|
DEPOSIT_SUBJECT = "Einzahlung" |
||||||
|
DESC = "Autorisiert von %s %s" |
||||||
|
|
||||||
|
amount = form.cleaned_data['credit_change'] |
||||||
|
|
||||||
|
print amount |
||||||
|
|
||||||
|
if amount is not None and amount != 0: |
||||||
|
if amount > 0: |
||||||
|
subject = DEPOSIT_SUBJECT |
||||||
|
else: |
||||||
|
subject = PAYOUT_SUBJECT |
||||||
|
|
||||||
|
obj.change_credit(amount, subject, DESC % (request.user.first_name, request.user.last_name)) |
||||||
|
|
||||||
|
|
||||||
class ProductBarcodeInline(admin.TabularInline): |
class ProductBarcodeInline(admin.TabularInline): |
||||||
model = ProductBarcode |
model = ProductBarcode |
||||||
extra = 1 |
extra = 1 |
||||||
|
|
||||||
|
|
||||||
class ProductAdmin(admin.ModelAdmin): |
class ProductAdmin(admin.ModelAdmin): |
||||||
list_display = ('name', 'category', 'price') |
list_display = ('name', 'category', 'price') |
||||||
list_filter = ['category'] |
list_filter = ['category'] |
||||||
inlines= [ProductBarcodeInline] |
inlines= [ProductBarcodeInline] |
||||||
|
|
||||||
|
|
||||||
class ProductCategoryAdmin(admin.ModelAdmin): |
class ProductCategoryAdmin(admin.ModelAdmin): |
||||||
list_display = ('name', 'comment') |
list_display = ('name', 'comment') |
||||||
|
|
||||||
|
|
||||||
class SalesLogEntryAdmin(admin.ModelAdmin): |
class SalesLogEntryAdmin(admin.ModelAdmin): |
||||||
list_display = ('account', 'timestamp', 'product', 'count', 'unit_price') |
list_display = ('account', 'timestamp', 'product', 'count', 'unit_price') |
||||||
list_filter = ['account', 'timestamp', 'product'] |
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(Account, AccountAdmin) |
||||||
admin.site.register(Product, ProductAdmin) |
admin.site.register(Product, ProductAdmin) |
||||||
admin.site.register(ProductBarcode) |
admin.site.register(ProductBarcode) |
||||||
admin.site.register(ProductCategory, ProductCategoryAdmin) |
admin.site.register(ProductCategory, ProductCategoryAdmin) |
||||||
admin.site.register(Transaction) |
admin.site.register(Transaction, TransactionAdmin) |
||||||
admin.site.register(SalesLogEntry, SalesLogEntryAdmin) |
admin.site.register(SalesLogEntry, SalesLogEntryAdmin) |
||||||
|
|
||||||
|
Loading…
Reference in new issue