You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.2 KiB
97 lines
3.2 KiB
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 |
|
from django.utils.translation import ugettext as _ |
|
from django.utils.translation import ugettext_lazy |
|
from django.utils.translation import ugettext_noop |
|
|
|
class AccountForm(forms.ModelForm): |
|
credit_change = forms.DecimalField(max_digits = 5, decimal_places = 2, |
|
required = False, |
|
label = ugettext_lazy('change change')) |
|
|
|
class Meta: |
|
model = Account |
|
|
|
class AccountAdmin(admin.ModelAdmin): |
|
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">%s</a>' % \ |
|
(reverse("admin:cash_transaction_changelist"), account.id, |
|
_('Transactions')) |
|
|
|
transaction_link.short_description = ugettext_lazy('Transaction link') |
|
|
|
transaction_link.allow_tags = True |
|
|
|
def save_model(self, request, obj, form, change): |
|
PAYOUT_SUBJECT = ugettext_noop('Payout') |
|
DEPOSIT_SUBJECT = ugettext_noop('Deposit') |
|
DESC = ugettext_noop('Authorized by %(first)s %(last)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', 'active') |
|
list_filter = ['category', 'active'] |
|
ordering = ('-active', 'name') |
|
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, TransactionAdmin) |
|
admin.site.register(SalesLogEntry, SalesLogEntryAdmin) |
|
|
|
|