mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-17 06:11:27 +01:00
Transfers are still two transactions, now linked to each other:
- shown as one item in lists, with each side's amount, account,
category and tags ("Combine transfers" user setting, on by default)
- date, reference date, paid and mute stay in sync between sides
- edit opens the transfer form; delete, restore, duplicate and bulk
actions act on both sides
- transfers made by the transfer form now trigger rules for each side
Recurring and quick transactions gain a Transfer type, with a "To
account" and optional "To amount", generating linked transfers. A
transfer can be converted into either.
Existing transfers are left as they are, since there is no reliable
way to pair them.
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().order_by(
|
|
"date",
|
|
"-type",
|
|
"-is_paid",
|
|
"id",
|
|
)
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/fragments/list_transactions.html",
|
|
context={
|
|
"date": date,
|
|
"transactions": transactions,
|
|
},
|
|
)
|