Пример #1
0
def result(request):
    user = Customer.objects.get(user=request.user)
    amount = request.POST.get("amount")
    acc = request.POST.get("acc")
    acc = str(acc)
    t = Transaction(previous_balance=Decimal(user.balance))
    t.amount = Decimal(amount)
    user2 = Customer.objects.get(account_no=acc)
    u2 = User.objects.get(username=user2.user.username)
    print(type(u2))
    amount = Decimal(amount)
    t2 = Transaction(previous_balance=Decimal(user2.balance))
    t2.amount = Decimal(amount)
    a = user.get_balance(amount, 1)
    if a == -1:
        messages.error(request, "No Balance!")
        return HttpResponseRedirect(reverse('customer:profile'))
    else:
        user.balance = a
        user2.balance = user2.get_balance(amount, 2)
        user2.save()
        t2.current_balance = Decimal(user2.balance)
        t2.user = u2
        t2.save()
        t2.transaction_id = t2.get_transaction_id()
        t2.type = 'Account Transfer'
        t2.save()
    user.save()
    t.current_balance = Decimal(user.balance)
    t.user = request.user
    t.save()
    t.transaction_id = t.get_transaction_id()
    t.type = 'Account Transfer'
    t.save()
    return HttpResponseRedirect(reverse('customer:profile'))
Пример #2
0
def amount2(request):
    user = Customer.objects.get(user=request.user)
    t = Transaction(previous_balance=Decimal(user.balance))
    amount = request.POST.get('deposit')
    t.amount = Decimal(amount)
    user.balance = user.get_balance(amount, 2)
    t.current_balance = Decimal(user.balance)
    t.user = request.user
    t.save()
    t.transaction_id = t.get_transaction_id()
    t.type = 'Deposit'
    t.save()
    user.save()
    return HttpResponseRedirect(reverse('customer:profile'))
Пример #3
0
def amount(request):
    user = Customer.objects.get(user=request.user)
    t = Transaction(previous_balance=Decimal(user.balance))
    withdraw = request.POST.get('withdraw')
    t.amount = Decimal(withdraw)
    a = user.get_balance(withdraw, 1)
    if a == -1:
        messages.error(request, "No Balance!")
    else:
        user.balance = a
    t.current_balance = Decimal(user.balance)
    t.user = request.user
    t.save()
    t.transaction_id = t.get_transaction_id()
    t.type = 'Withdrawal'
    t.save()
    user.save()
    return HttpResponseRedirect(reverse('customer:profile'))