Virtual Transaction: no more transaction to yourself

This commit is contained in:
tkroenert 2012-01-20 20:08:43 +01:00
parent 4269b67c90
commit 8a020a36b5
2 changed files with 4 additions and 2 deletions

View File

@ -25,7 +25,6 @@ class TransactionForm(forms.ModelForm):
class VirtualTransactionForm(forms.ModelForm):
""" ModelForm for :class:`Virtual Transactions <VirtualTransaction>` with a
currency field. """
recipient = forms.CharField(max_length=100)
amount = CurrencyField(label='Betrag')
class Meta:
@ -37,4 +36,6 @@ class VirtualTransactionForm(forms.ModelForm):
user = User.objects.get(username=self.cleaned_data['recipient'])
except User.DoesNotExist:
raise ValidationError(u"Emfpänger '%s' konnte nicht gefunden werden" % self.cleaned_data['recipient'])
if user == self.instance.user:
raise ValidationError(u"Emfpänger '%s' bist du selbst" % self.cleaned_data['recipient'])
return user

View File

@ -70,7 +70,8 @@ class VirtualTransaction(models.Model):
@staticmethod
def moveMoney(fromUser, toUser, amount, commit=True):
if fromUser != toUser:
print fromUser, toUser, fromUser == toUser, fromUser.id, toUser.id
if not (fromUser == toUser):
fromProfile = fromUser.get_profile()
toProfile = toUser.get_profile()
fromProfile.balance -= amount