Ejemplo n.º 1
0
 def clean(self):
     description = self.cleaned_data.get("description")
     amount = self.cleaned_data.get("amount")
     source = self.cleaned_data.get("sourceiban")
     destinationiban = self.cleaned_data.get("destinationiban")
     if source.user != self.request.user:
         raise ValidationError("This is not your Account")
     try:
         destination = Accounts.objects.get(iban = destinationiban)
     except Accounts.DoesNotExist:
         raise ValidationError("Wrong Destination IBAN")
     if source.amount > amount:
         transaction = Transaction()
         transaction.amount = amount
         transaction.description = description
         transaction.sourceaccount = source
         transaction.destinationaccount = destination
         transaction.currency_type = source.currency_type
         transaction.sending_date = date.today()
         transaction.make_transaction()
     else:
         raise ValidationError("Not Enough Account Balance")