Exemplo n.º 1
0
def payment(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = TransactionForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            try:
                #Retrieve transaction from form
                transaction = form.save(commit=False)
                #create factory
                factory = CommandFactory()
                #Try the transaction, if something goes wrong, an exception will be raised
                _make_transaction(request, transaction, factory)
                #Notify the transaction
                _notify_transaction(transaction, factory)
                
            except CommandError as ce:
                messages.error(request, ("Transfer unsuccesful: %s" % ce))
            except Exception as e:
                logging.error(e)
                messages.error(request, "Something went wrong, please try again")
            # redirect to a new URL:
            return HttpResponseRedirect(reverse('payments'))

    # if a GET (or any other method) we'll create a blank form
    else:
        form = TransactionForm()

    return render(request, 'accounts/payment.html', {'form': form})
Exemplo n.º 2
0
def update_transaction(request, pk):
    data = {}
    transaction = Transaction.objects.get(pk=pk)
    form = TransactionForm(request.POST or None, instance=transaction)

    if form.is_valid():
        form.save()
        return redirect('list-transactions')

    data['form'] = form
    data['transaction'] = transaction
    return render(request, 'accounts/form.html', data)
Exemplo n.º 3
0
def transaction_create(request, account_id):
    account = Account.get_by_id(int(account_id))
    if account is None:
        raise Http404
 
    if request.method == 'POST':
        t = Transaction(parent=account)
        form = TransactionForm(request.POST, instance=t)
        if form.is_valid():
            form.save(commit=False)
            t.setDate()
            t.save()
            logging.info('new transaction created - id: %s key: %s data: %s' % (t.key().id() , t.key(), t))
            return redirect('/accounts/'+account_id+'/transactions/')
    else:
        form = TransactionForm() 

    return render_to_response('accounts/transaction_create.html', RequestContext(request, { 'form':form }))
Exemplo n.º 4
0
def new_transaction(request):
    data = {}
    data['form'] = TransactionForm(request.POST or None)

    if data['form'].is_valid():
        data['form'].save()
        return redirect('list-transactions')

    return render(request, 'accounts/form.html', data)
Exemplo n.º 5
0
def withdraw_money(request, slug):
    account = get_object_or_404(BankAccount, slug=slug, owner=request.user)
    if request.method == 'POST':
        form = TransactionForm(request.POST,
                               request=request,
                               cat_type=settings.TR_WITHDRAW)
        if form.is_valid():
            cd = form.cleaned_data
            account.withdraw_money(amount=cd['amount'],
                                   currency=account.currency,
                                   tags=cd['tr_tags'],
                                   category=cd['category'],
                                   comment=cd['comment'])
            return redirect(reverse("accounts:list_"))
    else:
        form = TransactionForm(request=request, cat_type=settings.TR_WITHDRAW)
    return render(
        request, "accounts/money_transfer.html", {
            'account': account,
            'form': form,
            'msg': _('Withdraw money from "{}"'.format(account.label))
        })
Exemplo n.º 6
0
def newTransaction(request):
    form = TransactionForm(request.POST or None)
    if form.is_valid():
        newForm = form.save(commit=False)
        logger.error(newForm.account)
        account = Account.objects.get(account_Num=newForm.account.account_Num)

        account.balance = int(account.balance - form.cleaned_data['amount'])
        newForm.current_balance = account.balance

        newForm.save()

        account.save()
        return redirect('home')
    else:
        print(form.errors)
        form = TransactionForm()
        context = {'form': form}
    return render(request, 'AddTransaction.html', context)