Beispiel #1
0
def view_account(request, id):
    """
    View summary information for an account. The graph displayed along the top
    of the page shows income graphed over the previous year.
    """
    account = get_object_or_404(Account, pk=id, user=request.user)
    months, n = [], now()
    for o in reversed(range(0, -12, -1)):
        y, m = adjust_month(n.year, n.month, o)
        months.append({
            'url':
            reverse('ledger:view_month', kwargs={
                'year': y,
                'month': m,
            }),
            'year':
            y,
            'month':
            m,
            'amount':
            str(Transaction.month(y, m, account=account).sum()),
        })
    return render(request, 'ledger/pages/view_account.html', {
        'title': account,
        'account': account,
        'months': dumps(months),
    })
Beispiel #2
0
def view_month(request, year, month):
    """
    View transactions for a specific month.
    """
    year, month = int(year), int(month)
    transactions = Transaction.month(
        year,
        month,
        user=request.user,
        account__include_in_balance=True,
    )
    start = make_aware(datetime(year, month, 1))
    balance = Transaction.objects.filter(
        user=request.user,
        account__include_in_balance=True,
        date__lt=start,
    ).sum()
    return render(
        request, 'ledger/pages/view_month.html', {
            'title': start.strftime('%B %Y'),
            'transactions': transactions,
            'balance': balance,
            'prev_month': adjust_month(year, month, -1),
            'next_month': adjust_month(year, month, 1),
        })
Beispiel #3
0
def transfer(request):
    """
    Transfer an amount between accounts.
    """
    if request.method == 'POST':
        form = TransferForm(request.user, data=request.POST)
        if form.is_valid():
            from_account = form.cleaned_data['from_account']
            to_account = form.cleaned_data['to_account']
            date = form.cleaned_data['date']
            amount = form.cleaned_data['amount']
            from_transaction = Transaction(
                user=request.user,
                account=from_account,
                date=date,
                summary="Transfer to {}".format(to_account),
                amount=-amount,
            )
            from_transaction.save()
            to_transaction = Transaction(
                user=request.user,
                account=to_account,
                date=date,
                summary="Transfer from {}".format(from_account),
                amount=amount,
                linked=from_transaction,
            )
            to_transaction.save()
            from_transaction.linked = to_transaction
            from_transaction.save()
            return redirect(to_transaction)
    else:
        form = TransferForm(request.user, initial={'date': now()})
    return render(request, 'pages/form.html', {
        'title': "Transfer",
        'form': form,
    })
Beispiel #4
0
def view_account(request, id):
    """
    View summary information for an account. The graph displayed along the top
    of the page shows income graphed over the previous year.
    """
    account = get_object_or_404(Account, pk=id, user=request.user)
    months, n = [], now()
    for o in reversed(range(0, -12, -1)):
        y, m = adjust_month(n.year, n.month, o)
        months.append({
            'url': reverse('ledger:view_month', kwargs={
                'year': y,
                'month': m,
            }),
            'year': y,
            'month': m,
            'amount': str(Transaction.month(y, m, account=account).sum()),
        })
    return render(request, 'ledger/pages/view_account.html', {
        'title': account,
        'account': account,
        'months': dumps(months),
    })
Beispiel #5
0
def view_month(request, year, month):
    """
    View transactions for a specific month.
    """
    year, month = int(year), int(month)
    transactions = Transaction.month(
        year,
        month,
        user=request.user,
        account__include_in_balance=True,
    )
    start = make_aware(datetime(year, month, 1))
    balance = Transaction.objects.filter(
        user=request.user,
        account__include_in_balance=True,
        date__lt=start,
    ).sum()
    return render(request, 'ledger/pages/view_month.html', {
        'title': start.strftime('%B %Y'),
        'transactions': transactions,
        'balance': balance,
        'prev_month': adjust_month(year, month, -1),
        'next_month': adjust_month(year, month, 1),
    })
Beispiel #6
0
def transfer(request):
    """
    Transfer an amount between accounts.
    """
    if request.method == 'POST':
        form = TransferForm(request.user, data=request.POST)
        if form.is_valid():
            from_account = form.cleaned_data['from_account']
            to_account = form.cleaned_data['to_account']
            date = form.cleaned_data['date']
            amount = form.cleaned_data['amount']
            from_transaction = Transaction(
                user=request.user,
                account=from_account,
                date=date,
                summary="Transfer to {}".format(to_account),
                amount=-amount,
            )
            from_transaction.save()
            to_transaction = Transaction(
                user=request.user,
                account=to_account,
                date=date,
                summary="Transfer from {}".format(from_account),
                amount=amount,
            )
            to_transaction.save()
            to_transaction.links.add(from_transaction)
            to_transaction.save()
            from_transaction.links.add(to_transaction)
            from_transaction.save()
            return redirect(to_transaction)
    else:
        form = TransferForm(request.user, initial={'date': now()})
    return render(request, 'pages/form.html', {
        'title': "Transfer",
        'form': form,
    })