mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-21 08:01:45 +01:00
Splits a transaction into named parts whose amounts add up to its amount, e.g. the items of a big purchase or the fees inside an investment contribution. Parts can be set on transactions, installment plans, recurring and quick transactions, and are copied to the transactions they generate. Transfers can't have parts. Transactions show their parts under a tab on the card and in the investment detail. The content filter matches part names, and bulk edits leave the amount of split transactions alone.
84 lines
2.2 KiB
Python
84 lines
2.2 KiB
Python
import datetime
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.shortcuts import redirect, render
|
|
from django.utils import timezone
|
|
from django.views.decorators.http import require_http_methods
|
|
|
|
from apps.calendar_view.utils.calendar import get_transactions_by_day
|
|
from apps.transactions.models import Transaction
|
|
|
|
|
|
@login_required
|
|
def index(request):
|
|
now = timezone.localdate(timezone.now())
|
|
|
|
return redirect(to="calendar", month=now.month, year=now.year)
|
|
|
|
|
|
@login_required
|
|
@require_http_methods(["GET"])
|
|
def calendar(request, month: int, year: int):
|
|
if month < 1 or month > 12:
|
|
from django.http import Http404
|
|
|
|
raise Http404("Month is out of range")
|
|
|
|
next_month = 1 if month == 12 else month + 1
|
|
next_year = year + 1 if next_month == 1 and month == 12 else year
|
|
|
|
previous_month = 12 if month == 1 else month - 1
|
|
previous_year = year - 1 if previous_month == 12 and month == 1 else year
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/pages/calendar.html",
|
|
context={
|
|
"month": month,
|
|
"year": year,
|
|
"next_month": next_month,
|
|
"next_year": next_year,
|
|
"previous_month": previous_month,
|
|
"previous_year": previous_year,
|
|
},
|
|
)
|
|
|
|
|
|
@login_required
|
|
@require_http_methods(["GET"])
|
|
def calendar_list(request, month: int, year: int):
|
|
today = timezone.localdate(timezone.now())
|
|
dates = get_transactions_by_day(month=month, year=year)
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/fragments/list.html",
|
|
context={
|
|
"month": month,
|
|
"year": year,
|
|
"today": today,
|
|
"dates": dates,
|
|
},
|
|
)
|
|
|
|
|
|
@login_required
|
|
@require_http_methods(["GET"])
|
|
def calendar_transactions_list(request, day: int, month: int, year: int):
|
|
date = datetime.date(year=year, month=month, day=day)
|
|
transactions = Transaction.objects.filter(date=date).collapse_transfers().prefetch_related("sub_transactions").order_by(
|
|
"date",
|
|
"-type",
|
|
"-is_paid",
|
|
"id",
|
|
)
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/fragments/list_transactions.html",
|
|
context={
|
|
"date": date,
|
|
"transactions": transactions,
|
|
},
|
|
)
|