|
|
|
@ -1,16 +1,41 @@
@@ -1,16 +1,41 @@
|
|
|
|
|
from django.contrib import admin |
|
|
|
|
from cash.models import * |
|
|
|
|
from django import forms |
|
|
|
|
|
|
|
|
|
class AccountForm(forms.ModelForm): |
|
|
|
|
credit_change = forms.DecimalField(max_digits = 5, decimal_places = 2, required = False) |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = Account |
|
|
|
|
|
|
|
|
|
class AccountAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ('user', 'card_number', 'credit') |
|
|
|
|
form = AccountForm |
|
|
|
|
readonly_fields = ('credit',) |
|
|
|
|
|
|
|
|
|
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): |
|
|
|
|
model = ProductBarcode |
|
|
|
|
extra = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ('name', 'category', 'price') |
|
|
|
|
list_filter = ['category'] |
|
|
|
|