Home

mint @main - refs - log -
-
https://git.jolheiser.com/mint.git
Budget
tree log patch
fix copying to future year Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQA+RziVua4Q8LY2AxvR6reWWqjiFYE/+pmIc41eSbphO28HHfxXNvrDjwKUhgmEXCL 8RSbrV3+EM9blp82BsBA4= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
3 days ago
3 changed files, 34 additions(+), 24 deletions(-)
budget/static/budget/js/budget.jsbudget/utils.pybudget/views.py
M budget/static/budget/js/budget.js -> budget/static/budget/js/budget.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
diff --git a/budget/static/budget/js/budget.js b/budget/static/budget/js/budget.js
index 66f8b5434011a2785f328be054488898270a5d40..a07015242e0670dfc0358dd4545bc53312ff70da 100644
--- a/budget/static/budget/js/budget.js
+++ b/budget/static/budget/js/budget.js
@@ -48,10 +48,11 @@     confirmButtonText: "Yes",
     reverseButtons: true,
     showLoaderOnConfirm: true,
     preConfirm: () => {
+      const dt = calendar.getDate();
       fetch("/copy/", {
         method: "POST",
         headers: {"X-CSRFToken": csrftoken},
-        body: JSON.stringify({"month": calendar.getDate().getMonth() + 1}),
+        body: JSON.stringify({"month": dt.getMonth() + 1, "year": dt.getFullYear()}),
       }).then(() => calendar.refetchEvents());
     }
   });
@@ -234,4 +235,4 @@       }
     }
   }
   return cookieValue;
-}
\ No newline at end of file
+}
M budget/utils.py -> budget/utils.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
diff --git a/budget/utils.py b/budget/utils.py
index e4490956053d9985ae180772ce0eefaf27b449f8..3cf95a098bfbe0c58e3c1a8604e2cd48a9ddf71a 100644
--- a/budget/utils.py
+++ b/budget/utils.py
@@ -1,10 +1,9 @@
-from datetime import date, timedelta
 from calendar import monthrange
+from datetime import date, timedelta
 from typing import Tuple
 
 
-def prev_month_range(current_month: int) -> Tuple[date, date]:
-    current_year = date.today().year
+def prev_month_range(current_month: int, current_year: int) -> Tuple[date, date]:
     if current_month == 1:
         month = 12
         year = current_year - 1
@@ -15,9 +14,10 @@     first_day = date(year, month, 1)
     last_day = date(current_year, current_month, 1) - timedelta(days=1)
     return first_day, last_day
 
+
 def add_months(dt: date, months: int) -> date:
     month = dt.month - 1 + months
     year = dt.year + month // 12
     month = month % 12 + 1
     day = min(dt.day, monthrange(year, month)[1])
-    return date(year, month, day)
\ No newline at end of file
+    return date(year, month, day)
M budget/views.py -> budget/views.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/budget/views.py b/budget/views.py
index 567b95c0743eefde7782bb8dded67443a38bf530..45eff9a023d7afeb950604298d7ab4692c7dcb8c 100644
--- a/budget/views.py
+++ b/budget/views.py
@@ -1,14 +1,15 @@
+import json
+from datetime import date, datetime, timedelta
+
 from django.conf import settings
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.http import HttpRequest, HttpResponse, JsonResponse
 from django.shortcuts import render
-from django.contrib.auth.mixins import LoginRequiredMixin
 from django.urls import reverse
 from django.views import View
-from django.http import HttpRequest, JsonResponse, HttpResponse
-from datetime import date, datetime, timedelta
-from .models import Transaction, Recurrence
-import json
 
-from .utils import prev_month_range, add_months
+from .models import Recurrence, Transaction
+from .utils import add_months, prev_month_range
 
 BLUE = "#3788d8"
 YELLOW = "#d4a574"
@@ -20,13 +21,17 @@
 
 class IndexView(LoginRequiredMixin, View):
     def get(self, request: HttpRequest) -> HttpResponse:
-        return render(request, "budget/index.html", {
-            "json_ctx": {
-                "debug": settings.DEBUG,
-                "adminIndex": reverse("admin:index"),
-                "showAdmin": request.user.is_staff,
-            }
-        })
+        return render(
+            request,
+            "budget/index.html",
+            {
+                "json_ctx": {
+                    "debug": settings.DEBUG,
+                    "adminIndex": reverse("admin:index"),
+                    "showAdmin": request.user.is_staff,
+                }
+            },
+        )
 
 
 class EventsView(LoginRequiredMixin, View):
@@ -68,7 +73,6 @@         return JsonResponse(events, safe=False)
 
 
 class TransactionView(LoginRequiredMixin, View):
-
     def post(self, request: HttpRequest) -> HttpResponse:
         data = json.loads(request.body)
         props = data["extendedProps"]
@@ -114,9 +118,14 @@
 
 class CopyView(View):
     def post(self, request: HttpRequest):
-        month = json.loads(request.body)["month"]
-        first, last = prev_month_range(month)
-        transactions = Transaction.objects.filter(date__range=[first, last], recurrence__in=[Recurrence.WEEK, Recurrence.MONTH])
+        data = json.loads(request.body)
+        month = data["month"]
+        year = data["year"]
+        first, last = prev_month_range(month, year)
+        transactions = Transaction.objects.filter(
+            date__range=[first, last],
+            recurrence__in=[Recurrence.WEEK, Recurrence.MONTH],
+        )
         for transaction in transactions:
             if transaction.recurrence == Recurrence.MONTH:
                 transaction.id = None
@@ -133,4 +142,4 @@                         transaction.id = None
                         transaction.save()
                     else:
                         break
-        return HttpResponse()
\ No newline at end of file
+        return HttpResponse()