Browse Source

added credit change comment field

master
Frederic 11 years ago
parent
commit
3aa8efd92d
  1. 22
      cash/admin.py

22
cash/admin.py

@ -8,9 +8,12 @@ from django.utils.translation import ugettext_lazy @@ -8,9 +8,12 @@ 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'))
credit_change = forms.DecimalField(max_digits=5, decimal_places=2,
required=False,
label=ugettext_lazy('change change'))
credit_change_comment = forms.CharField(max_length=64, required=False,
label=ugettext_lazy('comment'))
class Meta:
model = Account
@ -19,6 +22,14 @@ class AccountAdmin(admin.ModelAdmin): @@ -19,6 +22,14 @@ class AccountAdmin(admin.ModelAdmin):
list_display = ('user', 'card_number', 'credit', 'transaction_link')
form = AccountForm
readonly_fields = ('credit',)
fieldsets = (
(None, {
'fields': ('user', 'card_number', 'pin', 'credit'),
}),
(ugettext_lazy('change change'), {
'fields': ('credit_change', 'credit_change_comment'),
}),
)
def transaction_link(self, account):
return '<a href="%s?account__id__exact=%d">%s</a>' % \
@ -35,8 +46,7 @@ class AccountAdmin(admin.ModelAdmin): @@ -35,8 +46,7 @@ class AccountAdmin(admin.ModelAdmin):
DESCRIPTION = ugettext_noop('Authorized by %(first)s %(last)s')
amount = form.cleaned_data['credit_change']
print amount
comment = form.cleaned_data['credit_change_comment']
if amount is not None and amount != 0:
if amount > 0:
@ -46,6 +56,8 @@ class AccountAdmin(admin.ModelAdmin): @@ -46,6 +56,8 @@ class AccountAdmin(admin.ModelAdmin):
desc = DESCRIPTION % {'first': request.user.first_name,
'last': request.user.last_name}
if comment is not None and len(comment) > 0:
desc += ' (%s)' % (comment)
obj.change_credit(amount, subject, desc)

Loading…
Cancel
Save