daftarche 0.35.2__tar.gz → 0.35.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {daftarche-0.35.2/src/daftarche.egg-info → daftarche-0.35.4}/PKG-INFO +4 -2
- {daftarche-0.35.2 → daftarche-0.35.4}/README.md +3 -1
- {daftarche-0.35.2 → daftarche-0.35.4}/pyproject.toml +1 -1
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/backup.py +66 -18
- daftarche-0.35.4/src/daftarche/data/user_guide.pdf +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/manage.py +71 -15
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/transactions.py +7 -2
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tx_list.py +6 -1
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/window.py +84 -30
- {daftarche-0.35.2 → daftarche-0.35.4/src/daftarche.egg-info}/PKG-INFO +4 -2
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche.egg-info/SOURCES.txt +3 -0
- daftarche-0.35.4/tests/test_account_blank_0353.py +48 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_backup.py +63 -8
- daftarche-0.35.4/tests/test_cats_edit_merchant_0354.py +46 -0
- daftarche-0.35.4/tests/test_lists_fit_0354.py +62 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_navigation.py +3 -2
- daftarche-0.35.2/src/daftarche/data/user_guide.pdf +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/LICENSE +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/setup.cfg +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/__init__.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/__main__.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/app_info.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/balance_check.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/category_dialog.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/chart_utils.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/data/icons/app_icon.png +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/data/icons/splash.png +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/db.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/icons.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/loans_dialog.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/logos.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/main.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/overview.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/past_categories.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/paths.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/phone.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/phone_link.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/phone_sync.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/phone_window.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/seal.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/split_dialog.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/style.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/__init__.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/accounts.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/chart_detail.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/charts.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/dashboard.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tabs/import_tab.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/tag_picker.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche/widgets.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche.egg-info/dependency_links.txt +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche.egg-info/entry_points.txt +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche.egg-info/requires.txt +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/src/daftarche.egg-info/top_level.txt +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_0350.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_category_dialog.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_charts.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_cli.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_columns.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_dates_transfers_parsing.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_db.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_demo_db.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_edit_merchant_0352.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_flagged_0333.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_help_menu.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_icons.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_loans.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_loans_icons_0344.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_logos_0340.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_manage_columns_0341.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_manage_lines_0310.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_manage_merchants.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_merchant.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_multi_import.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_newer_database_0331.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_no_category_0351.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_notes.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_open_database.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_overviews.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_past_categories_0320.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_phone.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_phone_link.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_pick_logos.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_qfx.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_robustness.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_rule_accounts_0330.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_rule_apply_0300.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_rules_0270.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_rules_merges.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_safety.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_set_merchant_0342.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_split.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_themes.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_totals_0332.py +0 -0
- {daftarche-0.35.2 → daftarche-0.35.4}/tests/test_transactions_0261.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: daftarche
|
|
3
|
-
Version: 0.35.
|
|
3
|
+
Version: 0.35.4
|
|
4
4
|
Summary: Daftarche: personal bookkeeping for bank transactions imported from QFX and Excel statements
|
|
5
5
|
Author-email: Vahid Anari <vahid.anari8@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -159,7 +159,9 @@ keeps its files in one folder:
|
|
|
159
159
|
|
|
160
160
|
On Windows the folder is `%APPDATA%\Daftarche`, on Linux `~/.local/share/daftarche`.
|
|
161
161
|
Set `DAFTARCHE_HOME` to use another folder, for example a test copy.
|
|
162
|
-
File →
|
|
162
|
+
File → Save Checkpoint (⌘S) keeps the data now among the copies made at each start, and Revert
|
|
163
|
+
to a Save… goes back to one of them; Back Up Database… and Restore Backup… save and load a copy
|
|
164
|
+
of the database by hand;
|
|
163
165
|
File → Open Database… shows a backup (through a copy) without changing anything.
|
|
164
166
|
The monthly snapshots sit on the same disk as the database; Settings → Extra
|
|
165
167
|
backup folder also copies them to a folder of your choice (iCloud Drive, an
|
|
@@ -117,7 +117,9 @@ keeps its files in one folder:
|
|
|
117
117
|
|
|
118
118
|
On Windows the folder is `%APPDATA%\Daftarche`, on Linux `~/.local/share/daftarche`.
|
|
119
119
|
Set `DAFTARCHE_HOME` to use another folder, for example a test copy.
|
|
120
|
-
File →
|
|
120
|
+
File → Save Checkpoint (⌘S) keeps the data now among the copies made at each start, and Revert
|
|
121
|
+
to a Save… goes back to one of them; Back Up Database… and Restore Backup… save and load a copy
|
|
122
|
+
of the database by hand;
|
|
121
123
|
File → Open Database… shows a backup (through a copy) without changing anything.
|
|
122
124
|
The monthly snapshots sit on the same disk as the database; Settings → Extra
|
|
123
125
|
backup folder also copies them to a folder of your choice (iCloud Drive, an
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "daftarche"
|
|
7
|
-
version = "0.35.
|
|
7
|
+
version = "0.35.4"
|
|
8
8
|
description = "Daftarche: personal bookkeeping for bank transactions imported from QFX and Excel statements"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
backups/daftarche-last.db overwritten at every start
|
|
4
4
|
backups/sessions/daftarche-2026-11-03-221500.db a start that found the data changed since
|
|
5
5
|
the last such copy; the newest KEEP_SESSIONS kept
|
|
6
|
+
backups/sessions/daftarche-2026-11-03-223000-saved.db File › Save Checkpoint, among them
|
|
6
7
|
backups/daily/daftarche-2026-11-03.db first start of each day; the newest KEEP_DAYS
|
|
7
8
|
backups/monthly/daftarche-2026-10.db first start of each month; the newest KEEP_MONTHS
|
|
8
9
|
|
|
@@ -18,6 +19,7 @@ gets a copy of the monthly snapshots too, with the same rotation; when the folde
|
|
|
18
19
|
|
|
19
20
|
import hashlib
|
|
20
21
|
import os
|
|
22
|
+
import re
|
|
21
23
|
import shutil
|
|
22
24
|
import sqlite3
|
|
23
25
|
import tempfile
|
|
@@ -29,11 +31,12 @@ from daftarche.paths import BACKUP_DIR
|
|
|
29
31
|
|
|
30
32
|
KEEP_MONTHS = 12
|
|
31
33
|
KEEP_DAYS = 14
|
|
32
|
-
KEEP_SESSIONS =
|
|
34
|
+
KEEP_SESSIONS = 20 # the data at the last starts and Save Checkpoints that found it changed
|
|
33
35
|
LAST_BACKUP = BACKUP_DIR / "daftarche-last.db"
|
|
34
36
|
MONTHLY_GLOB = "daftarche-????-??.db"
|
|
35
37
|
DAILY_GLOB = "daftarche-????-??-??.db"
|
|
36
|
-
|
|
38
|
+
SAVED = "-saved" # at the end of a session copy's name: made by Save Checkpoint
|
|
39
|
+
SESSION_NAME = re.compile(r"daftarche-\d{4}-\d\d-\d\d-\d{6}(-saved)?\.db") # nothing else there counts
|
|
37
40
|
|
|
38
41
|
|
|
39
42
|
def folder(kind: str) -> Path:
|
|
@@ -90,9 +93,66 @@ def _digest(path: Path) -> str | None:
|
|
|
90
93
|
return None
|
|
91
94
|
|
|
92
95
|
|
|
96
|
+
def _sessions_oldest_first() -> list[Path]:
|
|
97
|
+
"""The session copies in the order they were made: by when each file was written (the time in
|
|
98
|
+
its name is the clock's, which can go back: a time zone, the end of summer time)."""
|
|
99
|
+
where = folder("sessions")
|
|
100
|
+
if not where.is_dir():
|
|
101
|
+
return []
|
|
102
|
+
files = [f for f in where.iterdir() if SESSION_NAME.fullmatch(f.name)]
|
|
103
|
+
return sorted(files, key=lambda f: (f.stat().st_mtime_ns, f.name))
|
|
104
|
+
|
|
105
|
+
|
|
93
106
|
def session_backups() -> list[Path]:
|
|
94
|
-
"""The copies made at the last starts,
|
|
95
|
-
return
|
|
107
|
+
"""The copies made at the last starts and Save Checkpoints, the last made first."""
|
|
108
|
+
return _sessions_oldest_first()[::-1]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def session_info(path: Path) -> tuple[datetime | None, bool]:
|
|
112
|
+
"""(when a session copy was made, True when by Save Checkpoint) from its name."""
|
|
113
|
+
try:
|
|
114
|
+
when = datetime.strptime(path.name[10:27], "%Y-%m-%d-%H%M%S")
|
|
115
|
+
except ValueError:
|
|
116
|
+
when = None
|
|
117
|
+
return when, path.stem.endswith(SAVED)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _session_copy(source: Path, now: datetime, saved: bool) -> Path:
|
|
121
|
+
"""``source`` (a fresh copy of the data) kept in backups/sessions, unless the newest one there
|
|
122
|
+
holds the same data: then that one, and none is pushed out. Returns the session copy."""
|
|
123
|
+
sessions = session_backups()
|
|
124
|
+
newest = _digest(sessions[0]) if sessions else None
|
|
125
|
+
if newest is not None and newest == _digest(source):
|
|
126
|
+
return sessions[0]
|
|
127
|
+
while list(folder("sessions").glob(f"daftarche-{now:%Y-%m-%d-%H%M%S}*.db")): # two in one second
|
|
128
|
+
now += timedelta(seconds=1)
|
|
129
|
+
session = folder("sessions") / f"daftarche-{now:%Y-%m-%d-%H%M%S}{SAVED if saved else ''}.db"
|
|
130
|
+
_copy_file(source, session)
|
|
131
|
+
_keep_newest_sessions(session)
|
|
132
|
+
return session
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _keep_newest_sessions(made: Path) -> None:
|
|
136
|
+
"""The last KEEP_SESSIONS made; ``made``, just written, is always kept."""
|
|
137
|
+
others = [f for f in _sessions_oldest_first() if f != made]
|
|
138
|
+
for old in others[:max(0, len(others) - (KEEP_SESSIONS - 1))]:
|
|
139
|
+
old.unlink()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def save_checkpoint(conn: sqlite3.Connection, now: datetime | None = None) -> tuple[Path, bool]:
|
|
143
|
+
"""File › Save Checkpoint: the data now among the session copies. Returns (the copy, True
|
|
144
|
+
when it is new; False: nothing changed since the newest, which is returned)."""
|
|
145
|
+
now = now or datetime.now()
|
|
146
|
+
sessions = folder("sessions")
|
|
147
|
+
sessions.mkdir(parents=True, exist_ok=True)
|
|
148
|
+
fresh = sessions / f"daftarche-checkpoint-{now:%Y%m%d%H%M%S%f}.tmp"
|
|
149
|
+
try:
|
|
150
|
+
copy_db(conn, fresh)
|
|
151
|
+
before = session_backups()
|
|
152
|
+
copy = _session_copy(fresh, now, saved=True)
|
|
153
|
+
return copy, copy not in before
|
|
154
|
+
finally:
|
|
155
|
+
fresh.unlink(missing_ok=True)
|
|
96
156
|
|
|
97
157
|
|
|
98
158
|
def _move_old_monthly() -> None:
|
|
@@ -124,24 +184,12 @@ def mirror_snapshots(extra_dir: Path | str | None) -> list[Path]:
|
|
|
124
184
|
def startup_backup(conn: sqlite3.Connection, today: date | None = None,
|
|
125
185
|
extra_dir: Path | str | None = None, now: datetime | None = None) -> list[Path]:
|
|
126
186
|
"""The backups made at start-up; returns the files written, the second one always this
|
|
127
|
-
start's session copy (a new one, or the newest when nothing changed since: the same data)
|
|
128
|
-
for File › Revert to When Opened."""
|
|
187
|
+
start's session copy (a new one, or the newest when nothing changed since: the same data)."""
|
|
129
188
|
now = now or datetime.now()
|
|
130
189
|
today = today or now.date()
|
|
131
190
|
copy_db(conn, LAST_BACKUP)
|
|
132
191
|
written = [LAST_BACKUP]
|
|
133
|
-
|
|
134
|
-
newest = _digest(sessions[0]) if sessions else None
|
|
135
|
-
if newest is not None and newest == _digest(LAST_BACKUP):
|
|
136
|
-
written.append(sessions[0]) # nothing changed: no new copy, none pushed out
|
|
137
|
-
else:
|
|
138
|
-
session = folder("sessions") / f"daftarche-{now:%Y-%m-%d-%H%M%S}.db"
|
|
139
|
-
while session.exists(): # two starts in one second: the next free one
|
|
140
|
-
now += timedelta(seconds=1)
|
|
141
|
-
session = folder("sessions") / f"daftarche-{now:%Y-%m-%d-%H%M%S}.db"
|
|
142
|
-
_copy_file(LAST_BACKUP, session)
|
|
143
|
-
written.append(session)
|
|
144
|
-
_keep_newest(folder("sessions"), SESSION_GLOB, KEEP_SESSIONS, made=session)
|
|
192
|
+
written.append(_session_copy(LAST_BACKUP, now, saved=False)) # nothing changed: the newest
|
|
145
193
|
for kind, name, pattern, keep in (("daily", f"daftarche-{today:%Y-%m-%d}.db", DAILY_GLOB, KEEP_DAYS),
|
|
146
194
|
("monthly", f"daftarche-{today:%Y-%m}.db", MONTHLY_GLOB, KEEP_MONTHS)):
|
|
147
195
|
if kind == "monthly":
|
|
Binary file
|
|
@@ -6,8 +6,9 @@ from PySide6.QtWidgets import (
|
|
|
6
6
|
QHeaderView, QAbstractItemView, QMessageBox, QInputDialog,
|
|
7
7
|
QColorDialog, QCheckBox, QFormLayout, QLineEdit,
|
|
8
8
|
QDialogButtonBox, QFrame, QSizePolicy, QAbstractScrollArea, QRadioButton, QButtonGroup, QSplitter, QMenu,
|
|
9
|
+
QScrollArea,
|
|
9
10
|
)
|
|
10
|
-
from PySide6.QtCore import QByteArray, QItemSelectionModel, QSize, Qt
|
|
11
|
+
from PySide6.QtCore import QByteArray, QItemSelectionModel, QSize, Qt, QTimer
|
|
11
12
|
from PySide6.QtGui import QBrush, QColor, QFont, QFontMetrics, QPalette
|
|
12
13
|
|
|
13
14
|
from daftarche.style import get_settings
|
|
@@ -280,6 +281,7 @@ class ManageDialog(QDialog):
|
|
|
280
281
|
show_transactions=self._show_in_window)
|
|
281
282
|
self.tags_panel = TagsPanel(self.db, self._changed)
|
|
282
283
|
self.merchants_panel = MerchantsPanel(self.db, self._changed, self._show_merchant, notify=self.notify)
|
|
284
|
+
self.cats_panel.edit_merchant = self.merchants_panel.edit_named
|
|
283
285
|
|
|
284
286
|
self.tabs.addTab(self.accounts_panel, "🏦 Accounts")
|
|
285
287
|
self.tabs.addTab(self.cats_panel, "🏷️ Categories")
|
|
@@ -683,15 +685,25 @@ def _fit_beside(split):
|
|
|
683
685
|
split._fitted = True
|
|
684
686
|
|
|
685
687
|
|
|
688
|
+
class _RowOfLists(QHBoxLayout):
|
|
689
|
+
"""The row of Categories' lists, in a scroll area that scrolls it sideways. Its height is the
|
|
690
|
+
room there (each list scrolls its own lines), not its height for its width: that would count
|
|
691
|
+
every line of every list, and cut off a long list in a short window instead of scrolling it."""
|
|
692
|
+
|
|
693
|
+
def hasHeightForWidth(self):
|
|
694
|
+
return False
|
|
695
|
+
|
|
696
|
+
|
|
686
697
|
class CatsRulesPanel(QWidget):
|
|
687
698
|
"""Types, categories, sub-categories, and the merchants whose money goes there."""
|
|
688
699
|
M_NAME, M_TX, M_RULES, M_TOTAL = range(4)
|
|
689
700
|
|
|
690
|
-
def __init__(self, db, on_change, open_merchant=None, show_transactions=None):
|
|
701
|
+
def __init__(self, db, on_change, open_merchant=None, show_transactions=None, edit_merchant=None):
|
|
691
702
|
super().__init__()
|
|
692
703
|
self.db = db
|
|
693
704
|
self.on_change = on_change
|
|
694
705
|
self.open_merchant = open_merchant # (name) → Merchants tab
|
|
706
|
+
self.edit_merchant = edit_merchant # (name, parent) → its name after Edit Merchant, or None
|
|
695
707
|
self.show_transactions = show_transactions # (text, **filters) → the main window
|
|
696
708
|
self._build()
|
|
697
709
|
|
|
@@ -699,7 +711,7 @@ class CatsRulesPanel(QWidget):
|
|
|
699
711
|
outer = QVBoxLayout(self)
|
|
700
712
|
outer.setContentsMargins(10, 10, 10, 10)
|
|
701
713
|
lists = QWidget() # the four lists side by side; under them (when ticked), the transactions
|
|
702
|
-
lists_row =
|
|
714
|
+
lists_row = _RowOfLists(lists)
|
|
703
715
|
lists_row.setContentsMargins(0, 0, 0, 0)
|
|
704
716
|
lists_row.setSpacing(4)
|
|
705
717
|
|
|
@@ -761,7 +773,20 @@ class CatsRulesPanel(QWidget):
|
|
|
761
773
|
m_w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
762
774
|
lists_row.addWidget(m_w, 1)
|
|
763
775
|
self._lists = lists
|
|
764
|
-
|
|
776
|
+
self._list_cols = (type_w, cat_w, sub_w, m_w)
|
|
777
|
+
for table in (self.type_table, self.cat_table, self.sub_table, self.merchant_table):
|
|
778
|
+
# a list made long (or short again) by the window's height or the line under them
|
|
779
|
+
table.verticalScrollBar().rangeChanged.connect(lambda *_: QTimer.singleShot(0, self._fit_lists))
|
|
780
|
+
# a narrow window: the row of lists scrolls sideways as one (each list only up and down)
|
|
781
|
+
across = QScrollArea()
|
|
782
|
+
across.setFrameShape(QFrame.NoFrame)
|
|
783
|
+
across.setWidgetResizable(True)
|
|
784
|
+
across.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
785
|
+
across.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
|
786
|
+
across.setWidget(lists)
|
|
787
|
+
top = QWidget()
|
|
788
|
+
top_col = QVBoxLayout(top)
|
|
789
|
+
top_col.addWidget(across)
|
|
765
790
|
# the transactions under all the lists, across the whole width; the line between them drags
|
|
766
791
|
self.lines = TransactionList(self.db, self.on_change)
|
|
767
792
|
self.lines.btn_all.clicked.connect(self.merchant_table.clearSelection)
|
|
@@ -994,11 +1019,7 @@ class CatsRulesPanel(QWidget):
|
|
|
994
1019
|
break
|
|
995
1020
|
finally:
|
|
996
1021
|
self.merchant_table.blockSignals(False)
|
|
997
|
-
|
|
998
|
-
table.setMinimumWidth(table.sizeHint().width()) # never narrower than its text: no side scrolling
|
|
999
|
-
self._lists.layout().invalidate()
|
|
1000
|
-
self._lists.layout().activate()
|
|
1001
|
-
self._lists.setMinimumWidth(self._lists.layout().minimumSize().width()) # the window keeps room for them
|
|
1022
|
+
self._fit_lists()
|
|
1002
1023
|
self._update_lines()
|
|
1003
1024
|
|
|
1004
1025
|
# ── the transactions under the merchants ─────────────────────────────────
|
|
@@ -1025,6 +1046,20 @@ class CatsRulesPanel(QWidget):
|
|
|
1025
1046
|
self.lines.show_transactions(who + where, filters, hidden=("type", "category") + (("merchant",) if m else ())
|
|
1026
1047
|
+ (("subcategory",) if sub else ()))
|
|
1027
1048
|
|
|
1049
|
+
def _fit_lists(self):
|
|
1050
|
+
"""Each list as wide as its text (never cut, no side scrolling: its columns are laid out
|
|
1051
|
+
first, so a longer name chosen just now counts), and the row of them as wide as they are
|
|
1052
|
+
together: in a narrower window that row scrolls sideways. Its own scroll bar (a long
|
|
1053
|
+
list) is counted too, as the bar takes room from the columns."""
|
|
1054
|
+
for table in (self.type_table, self.cat_table, self.sub_table, self.merchant_table):
|
|
1055
|
+
table.resizeColumnsToContents()
|
|
1056
|
+
bar = table.verticalScrollBar()
|
|
1057
|
+
room = bar.width() if bar.maximum() > 0 else 0 # a long list: its bar is shown
|
|
1058
|
+
columns = sum(table.columnWidth(c) for c in range(table.columnCount()) if not table.isColumnHidden(c))
|
|
1059
|
+
table.setMinimumWidth(columns + room + 2 * table.frameWidth())
|
|
1060
|
+
# the row of lists: as wide as their minimums together, by Qt's own layout (the scroll
|
|
1061
|
+
# area around it keeps that width: no width set here, which would go stale)
|
|
1062
|
+
|
|
1028
1063
|
def _fill_merchants(self, cat_data=None, sub_data=None):
|
|
1029
1064
|
from daftarche.widgets import money
|
|
1030
1065
|
table = self.merchant_table
|
|
@@ -1068,8 +1103,22 @@ class CatsRulesPanel(QWidget):
|
|
|
1068
1103
|
if m and m["merchant"] and self.open_merchant:
|
|
1069
1104
|
items.insert(0, ("🏪 Its Rules (Merchants Tab)", lambda: self._merchant_double_clicked(row, self.M_NAME),
|
|
1070
1105
|
True))
|
|
1106
|
+
if m and m["merchant"] and self.edit_merchant: # the no-merchant line has no name to change
|
|
1107
|
+
items[:0] = [("✏️ Edit Merchant…", lambda: self._edit_merchant(m["merchant"]), True), None]
|
|
1071
1108
|
return items
|
|
1072
1109
|
|
|
1110
|
+
def _edit_merchant(self, name):
|
|
1111
|
+
"""Right-click › Edit Merchant…: its name and logo, as in the Merchants tab; the same
|
|
1112
|
+
merchant (by its new name) stays selected here."""
|
|
1113
|
+
new = self.edit_merchant(name, self)
|
|
1114
|
+
if not new:
|
|
1115
|
+
return
|
|
1116
|
+
for r in range(self.merchant_table.rowCount()):
|
|
1117
|
+
m = self.merchant_table.item(r, 0).data(Qt.UserRole)
|
|
1118
|
+
if m and m["merchant"] == new:
|
|
1119
|
+
self.merchant_table.selectRow(r)
|
|
1120
|
+
break
|
|
1121
|
+
|
|
1073
1122
|
def _merchant_double_clicked(self, row, col):
|
|
1074
1123
|
item = self.merchant_table.item(row, 0)
|
|
1075
1124
|
m = item.data(Qt.UserRole) if item else None
|
|
@@ -2363,14 +2412,21 @@ class MerchantsPanel(QWidget):
|
|
|
2363
2412
|
m = self._need()
|
|
2364
2413
|
if not m:
|
|
2365
2414
|
return
|
|
2366
|
-
|
|
2367
|
-
|
|
2415
|
+
name = self.edit_named(m["merchant"], self)
|
|
2416
|
+
if name:
|
|
2417
|
+
self.select(name)
|
|
2418
|
+
|
|
2419
|
+
def edit_named(self, old, parent):
|
|
2420
|
+
"""Edit Merchant for the merchant ``old`` (here, or from a right-click in Categories):
|
|
2421
|
+
its window over ``parent``; returns its name after OK (None: cancelled), the lists here
|
|
2422
|
+
and in the other tabs shown again."""
|
|
2423
|
+
dlg = LogoDialog(old, self.db.logo_for(old), self.db.logo_source(old), parent, edit_name=True)
|
|
2368
2424
|
if not dlg.exec():
|
|
2369
|
-
return
|
|
2425
|
+
return None
|
|
2370
2426
|
new = dlg.name
|
|
2371
2427
|
existing = next((x for x in self.db.get_merchants() if x.casefold() == new.casefold() and x != old), None)
|
|
2372
|
-
if existing and not _confirm_merge(
|
|
2373
|
-
return
|
|
2428
|
+
if existing and not _confirm_merge(parent, "merchant", old, existing, "transactions and rules"):
|
|
2429
|
+
return None
|
|
2374
2430
|
with self.db.transaction():
|
|
2375
2431
|
name = self.db.rename_merchant(old, new) if new != old else old
|
|
2376
2432
|
if dlg.logo_changed:
|
|
@@ -2381,7 +2437,7 @@ class MerchantsPanel(QWidget):
|
|
|
2381
2437
|
if name != old:
|
|
2382
2438
|
self._rename_flag(old, name)
|
|
2383
2439
|
self.on_change()
|
|
2384
|
-
|
|
2440
|
+
return name
|
|
2385
2441
|
|
|
2386
2442
|
def rename(self):
|
|
2387
2443
|
m = self._need()
|
|
@@ -1617,9 +1617,12 @@ class TransactionDialog(QDialog):
|
|
|
1617
1617
|
account_names = [a["name"] for a in self.db.get_accounts()]
|
|
1618
1618
|
self.f_account = SingleSelectCombo()
|
|
1619
1619
|
self.f_account.setEditable(True)
|
|
1620
|
+
# an empty line too: a transfer from outside your accounts has no From side (an income or
|
|
1621
|
+
# an expense still needs one: _save says so)
|
|
1620
1622
|
self._fill_account_combo(self.f_account, account_names,
|
|
1621
|
-
self.row["account"] if self.row else None,
|
|
1622
|
-
|
|
1623
|
+
self.row["account"] if self.row else None, blank=True)
|
|
1624
|
+
if not self.row and account_names:
|
|
1625
|
+
self.f_account.setCurrentIndex(1) # a new one: the first account, as before
|
|
1623
1626
|
self.f_account.setMaxVisibleItems(15)
|
|
1624
1627
|
|
|
1625
1628
|
# Transfer › Loans: one account, and which way the money went
|
|
@@ -1880,6 +1883,8 @@ class TransactionDialog(QDialog):
|
|
|
1880
1883
|
to_acc = None
|
|
1881
1884
|
elif not account and not to_acc:
|
|
1882
1885
|
raise ValueError("choose an account")
|
|
1886
|
+
elif not account and "Transfer" not in type_name:
|
|
1887
|
+
raise ValueError("choose the account (only a transfer from outside has none)")
|
|
1883
1888
|
if self._parts and "Transfer" in type_name:
|
|
1884
1889
|
raise ValueError("a transfer is not split: Join Again in Change Split… first")
|
|
1885
1890
|
if self._parts and not self._parts_changed and self.row and type_name != self.row["type"]:
|
|
@@ -12,6 +12,9 @@ from daftarche.widgets import FlowLayout, money
|
|
|
12
12
|
SHOW_KEY = "manage_show_transactions" # the "Show transactions" tick beside Manage's tabs
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
SLACK = 4 # pixels beyond the widest text of a column (see _fit_columns)
|
|
16
|
+
|
|
17
|
+
|
|
15
18
|
class _ManageTransactions(TransactionsTab):
|
|
16
19
|
"""The Transactions table, its filters set by Manage (``show``) instead of by its filter bar,
|
|
17
20
|
which is hidden. Edits made in it are saved and reported as in Transactions."""
|
|
@@ -112,7 +115,9 @@ class _ManageTransactions(TransactionsTab):
|
|
|
112
115
|
widest, at = width, i
|
|
113
116
|
width = header.sectionSizeHint(col)
|
|
114
117
|
if at is not None:
|
|
115
|
-
|
|
118
|
+
# a few pixels more: text is laid out to fractions of a pixel (a Retina screen),
|
|
119
|
+
# and a row the measure counted as narrower can need a pixel more ("…")
|
|
120
|
+
width = max(width, table.sizeHintForIndex(model.index(at, col)).width() + grid + SLACK)
|
|
116
121
|
header.resizeSection(col, width)
|
|
117
122
|
|
|
118
123
|
def _update_summary(self):
|
|
@@ -8,7 +8,7 @@ from PySide6.QtWidgets import (
|
|
|
8
8
|
QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout,
|
|
9
9
|
QHBoxLayout, QDialog, QFormLayout, QLabel,
|
|
10
10
|
QDialogButtonBox, QPushButton, QColorDialog, QFrame, QGridLayout,
|
|
11
|
-
QMessageBox, QFileDialog
|
|
11
|
+
QMessageBox, QFileDialog, QListWidget
|
|
12
12
|
)
|
|
13
13
|
from PySide6.QtCore import QSize, Qt, QTimer, QUrl
|
|
14
14
|
from PySide6.QtGui import QAction, QActionGroup, QColor, QDesktopServices, QFont, QKeySequence, QPalette
|
|
@@ -17,7 +17,8 @@ from sciwidgets.style import set_color_scheme
|
|
|
17
17
|
|
|
18
18
|
from daftarche.db import Database
|
|
19
19
|
from daftarche.app_info import APP, APP_NAME, APP_VERSION, USER_GUIDE
|
|
20
|
-
from daftarche.backup import copy_db, copy_for_viewing, mirror_snapshots, restore_backup,
|
|
20
|
+
from daftarche.backup import (copy_db, copy_for_viewing, mirror_snapshots, restore_backup, save_checkpoint,
|
|
21
|
+
session_backups, startup_backup)
|
|
21
22
|
from daftarche.overview import UnmatchedTransfersDialog
|
|
22
23
|
from daftarche.phone_sync import PhoneSender
|
|
23
24
|
from daftarche.paths import BACKUP_DIR, DATA_DIR, DB_PATH
|
|
@@ -106,10 +107,10 @@ class MainWindow(QMainWindow):
|
|
|
106
107
|
add(file_menu, "Open Database…", self.open_database, QKeySequence("Ctrl+O"))
|
|
107
108
|
self.back_action = add(file_menu, "Back to My Database", self.back_to_my_database, QKeySequence("Ctrl+Shift+O"))
|
|
108
109
|
file_menu.addSeparator()
|
|
109
|
-
self.
|
|
110
|
+
self.checkpoint_action = add(file_menu, "Save Checkpoint", self._save_checkpoint, QKeySequence("Ctrl+S"))
|
|
111
|
+
self.revert_action = add(file_menu, "Revert to a Save…", self._revert_to_save) # no shortcut: it replaces data
|
|
112
|
+
self.backup_action = add(file_menu, "Back Up Database…", self._save_backup, QKeySequence("Ctrl+Shift+S"))
|
|
110
113
|
self.restore_action = add(file_menu, "Restore Backup…", self._restore_backup) # no shortcut: it replaces data
|
|
111
|
-
self.revert_action = add(file_menu, "Revert to When Opened…", self._revert_to_opened)
|
|
112
|
-
self.revert_action.setEnabled(self._opened_copy is not None)
|
|
113
114
|
file_menu.addSeparator()
|
|
114
115
|
add(file_menu, "Show Data Folder", self._show_data_folder)
|
|
115
116
|
file_menu.addSeparator()
|
|
@@ -395,9 +396,8 @@ class MainWindow(QMainWindow):
|
|
|
395
396
|
self.view_label.setToolTip(str(self.viewing))
|
|
396
397
|
self.setWindowTitle(f"{APP_NAME} — {self.viewing.name} (copy)" if viewing else APP_NAME)
|
|
397
398
|
self.back_action.setEnabled(viewing)
|
|
398
|
-
for action in (self.backup_action, self.restore_action):
|
|
399
|
-
action.setEnabled(not viewing)
|
|
400
|
-
self.revert_action.setEnabled(not viewing and self._opened_copy is not None)
|
|
399
|
+
for action in (self.backup_action, self.restore_action, self.checkpoint_action, self.revert_action):
|
|
400
|
+
action.setEnabled(not viewing) # about your own database
|
|
401
401
|
self.setAcceptDrops(not viewing)
|
|
402
402
|
|
|
403
403
|
def _switch_to(self, db):
|
|
@@ -455,33 +455,38 @@ class MainWindow(QMainWindow):
|
|
|
455
455
|
if destination_path:
|
|
456
456
|
copy_db(self.db.conn, destination_path)
|
|
457
457
|
|
|
458
|
-
_opened_copy = None # this start's copy of the data (File › Revert to When Opened)
|
|
459
|
-
_opened_at = None
|
|
460
|
-
|
|
461
458
|
def _auto_backup(self):
|
|
462
459
|
try:
|
|
463
|
-
|
|
464
|
-
self._opened_copy, self._opened_at = written[1], datetime.now()
|
|
460
|
+
startup_backup(self.db.conn, extra_dir=self.settings.get("backup_extra_dir"))
|
|
465
461
|
except Exception as exc: # the app still opens, but the problem stays in sight
|
|
466
462
|
self.statusBar().showMessage(f"⚠️ Automatic backup failed: {exc}")
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
QMessageBox.
|
|
463
|
+
|
|
464
|
+
def _save_checkpoint(self):
|
|
465
|
+
"""File › Save Checkpoint (⌘S): the data now among the copies made at each start (the
|
|
466
|
+
last 20), to go back to with Revert to a Save…; nothing new when nothing changed."""
|
|
467
|
+
try:
|
|
468
|
+
copy, new = save_checkpoint(self.db.conn)
|
|
469
|
+
except Exception as exc:
|
|
470
|
+
QMessageBox.critical(self, "Save Checkpoint", f"Could not save a copy:\n{exc}")
|
|
475
471
|
return
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
472
|
+
from daftarche.backup import session_info
|
|
473
|
+
when, _saved = session_info(copy)
|
|
474
|
+
at = when.strftime("%H:%M") if when else ""
|
|
475
|
+
self.statusBar().showMessage(f"✓ Saved at {at}" if new else f"✓ Nothing changed since the copy of {at}",
|
|
476
|
+
5000)
|
|
477
|
+
|
|
478
|
+
def _revert_to_save(self):
|
|
479
|
+
"""File › Revert to a Save…: the data as it was at one of the last starts or Save
|
|
480
|
+
Checkpoints (the newest chosen at first), after asking; what is there now is kept as a
|
|
481
|
+
copy first, as with Restore."""
|
|
482
|
+
copies = session_backups()
|
|
483
|
+
if not copies:
|
|
484
|
+
QMessageBox.information(self, "Revert", "There is no saved copy yet: File → Save Checkpoint makes one.")
|
|
485
|
+
return
|
|
486
|
+
dlg = RevertDialog(copies, self)
|
|
487
|
+
if not dlg.exec() or dlg.chosen is None:
|
|
488
|
+
return
|
|
489
|
+
self._replace_data(dlg.chosen)
|
|
485
490
|
|
|
486
491
|
def _save_backup(self):
|
|
487
492
|
path, _ = QFileDialog.getSaveFileName(
|
|
@@ -543,6 +548,55 @@ class MainWindow(QMainWindow):
|
|
|
543
548
|
"in the backups folder.")
|
|
544
549
|
|
|
545
550
|
|
|
551
|
+
class RevertDialog(QDialog):
|
|
552
|
+
"""File › Revert to a Save…: the copies made at each start and Save Checkpoint, the newest
|
|
553
|
+
first and chosen; Revert asks once more, then ``chosen`` is the copy."""
|
|
554
|
+
|
|
555
|
+
def __init__(self, copies, parent=None):
|
|
556
|
+
super().__init__(parent)
|
|
557
|
+
from daftarche.backup import session_info
|
|
558
|
+
self.setWindowTitle("Revert to a Save")
|
|
559
|
+
self.copies, self.chosen = list(copies), None
|
|
560
|
+
layout = QVBoxLayout(self)
|
|
561
|
+
intro = QLabel("Go back to your data as it was then. Everything changed since is undone; "
|
|
562
|
+
"what is there now is saved first, so this can be undone too.")
|
|
563
|
+
intro.setWordWrap(True)
|
|
564
|
+
layout.addWidget(intro)
|
|
565
|
+
self.list = QListWidget()
|
|
566
|
+
today = datetime.now().date()
|
|
567
|
+
for path in self.copies:
|
|
568
|
+
when, saved = session_info(path)
|
|
569
|
+
if when is None:
|
|
570
|
+
text = path.name
|
|
571
|
+
else:
|
|
572
|
+
day = "Today" if when.date() == today else f"{when:%a %b} {when.day}, {when.year}"
|
|
573
|
+
text = f"{day} {when:%H:%M:%S} — {'Saved' if saved else 'Opened'}"
|
|
574
|
+
self.list.addItem(text)
|
|
575
|
+
self.list.setCurrentRow(0)
|
|
576
|
+
self.list.itemDoubleClicked.connect(lambda _item: self._revert())
|
|
577
|
+
layout.addWidget(self.list, 1)
|
|
578
|
+
row = QHBoxLayout()
|
|
579
|
+
row.addStretch()
|
|
580
|
+
cancel = QPushButton("Cancel")
|
|
581
|
+
cancel.setProperty("class", "secondary")
|
|
582
|
+
cancel.clicked.connect(self.reject)
|
|
583
|
+
revert = QPushButton("Revert…")
|
|
584
|
+
revert.clicked.connect(self._revert)
|
|
585
|
+
row.addWidget(cancel)
|
|
586
|
+
row.addWidget(revert)
|
|
587
|
+
layout.addLayout(row)
|
|
588
|
+
self.resize(460, 420)
|
|
589
|
+
|
|
590
|
+
def _revert(self):
|
|
591
|
+
r = self.list.currentRow()
|
|
592
|
+
if r < 0:
|
|
593
|
+
return
|
|
594
|
+
if QMessageBox.question(self, "Revert", f"Go back to your data of {self.list.item(r).text().split(' —')[0]}?",
|
|
595
|
+
QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
|
|
596
|
+
self.chosen = self.copies[r]
|
|
597
|
+
self.accept()
|
|
598
|
+
|
|
599
|
+
|
|
546
600
|
class ImportDialog(QDialog):
|
|
547
601
|
"""File → Import Statement…: the statement preview and import, in a window of its own."""
|
|
548
602
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: daftarche
|
|
3
|
-
Version: 0.35.
|
|
3
|
+
Version: 0.35.4
|
|
4
4
|
Summary: Daftarche: personal bookkeeping for bank transactions imported from QFX and Excel statements
|
|
5
5
|
Author-email: Vahid Anari <vahid.anari8@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -159,7 +159,9 @@ keeps its files in one folder:
|
|
|
159
159
|
|
|
160
160
|
On Windows the folder is `%APPDATA%\Daftarche`, on Linux `~/.local/share/daftarche`.
|
|
161
161
|
Set `DAFTARCHE_HOME` to use another folder, for example a test copy.
|
|
162
|
-
File →
|
|
162
|
+
File → Save Checkpoint (⌘S) keeps the data now among the copies made at each start, and Revert
|
|
163
|
+
to a Save… goes back to one of them; Back Up Database… and Restore Backup… save and load a copy
|
|
164
|
+
of the database by hand;
|
|
163
165
|
File → Open Database… shows a backup (through a copy) without changing anything.
|
|
164
166
|
The monthly snapshots sit on the same disk as the database; Settings → Extra
|
|
165
167
|
backup folder also copies them to a folder of your choice (iCloud Drive, an
|
|
@@ -45,8 +45,10 @@ src/daftarche/tabs/import_tab.py
|
|
|
45
45
|
src/daftarche/tabs/manage.py
|
|
46
46
|
src/daftarche/tabs/transactions.py
|
|
47
47
|
tests/test_0350.py
|
|
48
|
+
tests/test_account_blank_0353.py
|
|
48
49
|
tests/test_backup.py
|
|
49
50
|
tests/test_category_dialog.py
|
|
51
|
+
tests/test_cats_edit_merchant_0354.py
|
|
50
52
|
tests/test_charts.py
|
|
51
53
|
tests/test_cli.py
|
|
52
54
|
tests/test_columns.py
|
|
@@ -57,6 +59,7 @@ tests/test_edit_merchant_0352.py
|
|
|
57
59
|
tests/test_flagged_0333.py
|
|
58
60
|
tests/test_help_menu.py
|
|
59
61
|
tests/test_icons.py
|
|
62
|
+
tests/test_lists_fit_0354.py
|
|
60
63
|
tests/test_loans.py
|
|
61
64
|
tests/test_loans_icons_0344.py
|
|
62
65
|
tests/test_logos_0340.py
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""0.35.3: an income can be made a transfer from outside: the edit window's Account can be empty."""
|
|
2
|
+
|
|
3
|
+
from unittest import mock
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from conftest import keep
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.fixture(scope="module")
|
|
11
|
+
def qapp():
|
|
12
|
+
from PySide6.QtWidgets import QApplication
|
|
13
|
+
return QApplication.instance() or QApplication([])
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_income_into_a_transfer_from_outside(qapp, db):
|
|
17
|
+
from daftarche.tabs.transactions import TransactionDialog
|
|
18
|
+
db.get_or_create_account("Chequing")
|
|
19
|
+
uc, us = db.get_uncategorized_ids()
|
|
20
|
+
tx = db.add_transaction(2026, "May", 1, "Income", "Chequing", 5000, us, uc, merchant="Wallet")
|
|
21
|
+
db.conn.commit()
|
|
22
|
+
row = next(r for r in db.get_transactions() if r["id"] == tx)
|
|
23
|
+
d = keep(TransactionDialog(db, row))
|
|
24
|
+
assert d.f_account.findText("") == 0 and d.f_account.currentText() == "Chequing"
|
|
25
|
+
d.f_type.setCurrentText("Transfer")
|
|
26
|
+
d.f_account.setCurrentText("")
|
|
27
|
+
d.f_to_account.setCurrentText("Chequing")
|
|
28
|
+
d.f_category.setCurrentText("External Transfer")
|
|
29
|
+
with mock.patch.object(d, "accept"):
|
|
30
|
+
d._save()
|
|
31
|
+
r = db.conn.execute("SELECT account_id, to_account_id, amount FROM transactions WHERE id=?", (tx,)).fetchone()
|
|
32
|
+
assert r["account_id"] is None and r["to_account_id"] == db.get_account_by_name("Chequing")["id"]
|
|
33
|
+
assert db.get_current_total_balance() == 5000 # the balance as before
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_an_income_still_needs_its_account(qapp, db):
|
|
37
|
+
from daftarche.tabs.transactions import TransactionDialog
|
|
38
|
+
db.get_or_create_account("Chequing")
|
|
39
|
+
uc, us = db.get_uncategorized_ids()
|
|
40
|
+
tx = db.add_transaction(2026, "May", 1, "Income", "Chequing", 50, us, uc)
|
|
41
|
+
db.conn.commit()
|
|
42
|
+
d = keep(TransactionDialog(db, next(r for r in db.get_transactions() if r["id"] == tx)))
|
|
43
|
+
d.f_account.setCurrentText("")
|
|
44
|
+
with mock.patch.object(d, "accept") as accepted, mock.patch("daftarche.tabs.transactions.QMessageBox") as box:
|
|
45
|
+
d._save()
|
|
46
|
+
assert not accepted.called and box.warning.called or box.critical.called
|
|
47
|
+
new = keep(TransactionDialog(db, None))
|
|
48
|
+
assert new.f_account.currentText() == "Chequing" # a new one: the first account, as before
|
|
@@ -116,7 +116,8 @@ def test_a_copy_at_each_start_that_changed_something(folder, conn):
|
|
|
116
116
|
written = backup.startup_backup(conn, now=start + timedelta(hours=i))
|
|
117
117
|
kept = backup.session_backups()
|
|
118
118
|
assert len(kept) == backup.KEEP_SESSIONS and kept[0] == written[1]
|
|
119
|
-
|
|
119
|
+
last = start + timedelta(hours=backup.KEEP_SESSIONS + 2)
|
|
120
|
+
assert kept[0].name == f"daftarche-{last:%Y-%m-%d-%H%M%S}.db" and kept[0].parent == folder / "sessions"
|
|
120
121
|
copy = sqlite3.connect(kept[-1])
|
|
121
122
|
assert copy.execute("SELECT x FROM t").fetchone() == (3,) # the oldest kept: the 4th start
|
|
122
123
|
copy.close()
|
|
@@ -149,8 +150,9 @@ def test_older_monthly_copies_move_into_their_folder(folder, conn):
|
|
|
149
150
|
assert not (folder / "daftarche-2026-09.db").exists()
|
|
150
151
|
|
|
151
152
|
|
|
152
|
-
def
|
|
153
|
-
"""File ›
|
|
153
|
+
def test_save_checkpoint_and_revert_to_a_save(qapp, monkeypatch, tmp_path):
|
|
154
|
+
"""0.35.4: File › Save Checkpoint keeps the data now among the session copies (none when
|
|
155
|
+
nothing changed); Revert to a Save… lists them, the newest chosen, asks, then puts one back."""
|
|
154
156
|
from unittest import mock
|
|
155
157
|
|
|
156
158
|
from PySide6.QtWidgets import QMessageBox
|
|
@@ -161,20 +163,49 @@ def test_revert_to_when_opened(qapp, monkeypatch, tmp_path):
|
|
|
161
163
|
monkeypatch.setattr(window_module, "BACKUP_DIR", tmp_path / "backups")
|
|
162
164
|
monkeypatch.setattr(window_module, "DB_PATH", tmp_path / "w.db")
|
|
163
165
|
w = window_module.MainWindow()
|
|
164
|
-
|
|
166
|
+
opened = backup.session_backups()
|
|
167
|
+
assert len(opened) == 1 and backup.session_info(opened[0])[1] is False # made when opened
|
|
168
|
+
w._save_checkpoint() # nothing changed: no new copy
|
|
169
|
+
assert backup.session_backups() == opened and "Nothing changed" in w.statusBar().currentMessage()
|
|
165
170
|
w.db.get_or_create_account("Card")
|
|
166
171
|
w.db.conn.commit()
|
|
172
|
+
w._save_checkpoint()
|
|
173
|
+
copies = backup.session_backups()
|
|
174
|
+
assert len(copies) == 2 and backup.session_info(copies[0])[1] is True and "Saved at" in w.statusBar().currentMessage()
|
|
175
|
+
w.db.get_or_create_account("Cash")
|
|
176
|
+
w.db.conn.commit()
|
|
177
|
+
dlg = window_module.RevertDialog(copies, w)
|
|
178
|
+
assert dlg.list.currentRow() == 0 and "Saved" in dlg.list.item(0).text() and "Opened" in dlg.list.item(1).text()
|
|
167
179
|
with mock.patch.object(window_module.QMessageBox, "question", return_value=QMessageBox.No):
|
|
168
|
-
|
|
169
|
-
assert
|
|
170
|
-
with mock.patch.object(window_module
|
|
180
|
+
dlg._revert()
|
|
181
|
+
assert dlg.chosen is None
|
|
182
|
+
with mock.patch.object(window_module, "RevertDialog", return_value=mock.Mock(exec=lambda: True, chosen=copies[0])), \
|
|
183
|
+
mock.patch.object(window_module.QMessageBox, "information"):
|
|
184
|
+
w._revert_to_save() # the Save: Card is there, Cash is not
|
|
185
|
+
assert w.db.get_account_by_name("Card") and not w.db.get_account_by_name("Cash")
|
|
186
|
+
with mock.patch.object(window_module, "RevertDialog", return_value=mock.Mock(exec=lambda: True, chosen=copies[1])), \
|
|
171
187
|
mock.patch.object(window_module.QMessageBox, "information"):
|
|
172
|
-
w.
|
|
188
|
+
w._revert_to_save() # when it was opened: neither
|
|
173
189
|
assert not w.db.get_account_by_name("Card")
|
|
174
190
|
assert list((tmp_path / "backups").glob("daftarche-before-restore-*.db")) # what was there, kept
|
|
175
191
|
w.close()
|
|
176
192
|
|
|
177
193
|
|
|
194
|
+
def test_saves_share_the_twenty(folder, conn):
|
|
195
|
+
from datetime import datetime, timedelta
|
|
196
|
+
start = datetime(2026, 11, 4, 9, 0, 0)
|
|
197
|
+
backup.startup_backup(conn, now=start)
|
|
198
|
+
for i in range(backup.KEEP_SESSIONS + 5):
|
|
199
|
+
conn.execute("UPDATE t SET x = ?", (1000 + i,))
|
|
200
|
+
conn.commit()
|
|
201
|
+
copy, new = backup.save_checkpoint(conn, now=start + timedelta(minutes=i + 1))
|
|
202
|
+
assert new
|
|
203
|
+
kept = backup.session_backups()
|
|
204
|
+
assert len(kept) == backup.KEEP_SESSIONS == 20 and kept[0] == copy and kept[0].name.endswith("-saved.db")
|
|
205
|
+
assert backup.save_checkpoint(conn, now=start + timedelta(hours=5)) == (copy, False)
|
|
206
|
+
assert not list((folder / "sessions").glob("*.tmp"))
|
|
207
|
+
|
|
208
|
+
|
|
178
209
|
def test_a_damaged_copy_or_a_clock_set_back_loses_nothing(folder, conn):
|
|
179
210
|
"""A broken newest copy (a full disk) does not stop the backups; a clock set back keeps the new
|
|
180
211
|
copy; two starts in one second make two copies."""
|
|
@@ -198,3 +229,27 @@ def test_a_damaged_copy_or_a_clock_set_back_loses_nothing(folder, conn):
|
|
|
198
229
|
twice = backup.startup_backup(conn, now=datetime(2026, 11, 3, 9, 0, 0))
|
|
199
230
|
assert twice[1].name == "daftarche-2026-11-03-090001.db" and twice[1].exists() # not over the other
|
|
200
231
|
assert not list(folder.rglob("*.part"))
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_a_clock_moved_back_keeps_the_last_saves(folder, conn):
|
|
235
|
+
"""Copies are kept and listed in the order they were made, not by the time in their names
|
|
236
|
+
(a time zone or the end of summer time sets the clock back); other files there do not count."""
|
|
237
|
+
from datetime import datetime, timedelta
|
|
238
|
+
late = datetime(2026, 11, 4, 18, 0, 0)
|
|
239
|
+
for i in range(backup.KEEP_SESSIONS):
|
|
240
|
+
conn.execute("UPDATE t SET x = ?", (i,))
|
|
241
|
+
conn.commit()
|
|
242
|
+
backup.save_checkpoint(conn, now=late + timedelta(minutes=i))
|
|
243
|
+
made = []
|
|
244
|
+
for i in range(3): # six hours west: the clock says 13:00
|
|
245
|
+
conn.execute("UPDATE t SET x = ?", (100 + i,))
|
|
246
|
+
conn.commit()
|
|
247
|
+
made.append(backup.save_checkpoint(conn, now=datetime(2026, 11, 4, 13, i, 0))[0])
|
|
248
|
+
kept = backup.session_backups()
|
|
249
|
+
assert kept[:3] == made[::-1] and len(kept) == backup.KEEP_SESSIONS
|
|
250
|
+
copy = sqlite3.connect(kept[0])
|
|
251
|
+
assert copy.execute("SELECT x FROM t").fetchone() == (102,) # Revert's first row: the last saved
|
|
252
|
+
copy.close()
|
|
253
|
+
assert backup.save_checkpoint(conn, now=datetime(2026, 11, 4, 13, 5, 0)) == (made[-1], False)
|
|
254
|
+
(folder / "sessions" / "daftarche-2026-11-04-130000 copy.db").write_bytes(b"mine")
|
|
255
|
+
assert all(p.name != "daftarche-2026-11-04-130000 copy.db" for p in backup.session_backups())
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""0.35.4: right-click a merchant in Manage › Categories › Edit Merchant… (name and logo, as in the
|
|
2
|
+
Merchants tab); it stays selected under its new name. The no-merchant line has no such item."""
|
|
3
|
+
|
|
4
|
+
from unittest import mock
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from conftest import keep
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture(scope="module")
|
|
12
|
+
def qapp():
|
|
13
|
+
from PySide6.QtWidgets import QApplication
|
|
14
|
+
return QApplication.instance() or QApplication([])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_edit_merchant_from_categories(qapp, db):
|
|
18
|
+
from daftarche.tabs.manage import ManageDialog
|
|
19
|
+
db.get_or_create_account("Card")
|
|
20
|
+
db.add_category("Food", "Expense")
|
|
21
|
+
food = db.get_category_by_name("Food", type_name="Expense")["id"]
|
|
22
|
+
sub = db.uncategorized_subcategory(food)["id"]
|
|
23
|
+
db.add_transaction(2026, "May", 1, "Expense", "Card", 10, sub, food, merchant="Second cup")
|
|
24
|
+
db.add_transaction(2026, "May", 2, "Expense", "Card", 5, sub, food)
|
|
25
|
+
db.conn.commit()
|
|
26
|
+
m = keep(ManageDialog(db, lambda: None))
|
|
27
|
+
p = m.cats_panel
|
|
28
|
+
types = {p.type_table.item(r, 0).text(): r for r in range(p.type_table.rowCount())}
|
|
29
|
+
p.type_table.selectRow(types["Expense"])
|
|
30
|
+
cats = {p.cat_table.item(r, 0).text(): r for r in range(p.cat_table.rowCount())}
|
|
31
|
+
p.cat_table.selectRow(cats["Food"])
|
|
32
|
+
names = [p.merchant_table.item(r, 0).text() for r in range(p.merchant_table.rowCount())]
|
|
33
|
+
p.merchant_table.selectRow(names.index("Second cup"))
|
|
34
|
+
menu = p._merchant_menu()
|
|
35
|
+
assert menu[0][0] == "✏️ Edit Merchant…"
|
|
36
|
+
dlg = mock.Mock(exec=mock.Mock(return_value=True), image=None, logo_changed=False, source="")
|
|
37
|
+
dlg.name = "Second Cup"
|
|
38
|
+
with mock.patch("daftarche.tabs.manage.LogoDialog", return_value=dlg) as window:
|
|
39
|
+
menu[0][1]()
|
|
40
|
+
assert window.call_args.args[0] == "Second cup" and window.call_args.args[3] is p # over Categories
|
|
41
|
+
assert "Second Cup" in db.get_merchants() and "Second cup" not in db.get_merchants()
|
|
42
|
+
chosen = p._selected_data(p.merchant_table)
|
|
43
|
+
assert chosen and chosen["merchant"] == "Second Cup"
|
|
44
|
+
names = [p.merchant_table.item(r, 0).text() for r in range(p.merchant_table.rowCount())]
|
|
45
|
+
p.merchant_table.selectRow(names.index("(no merchant)"))
|
|
46
|
+
assert all(item is None or "Edit Merchant" not in item[0] for item in p._merchant_menu())
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""0.35.4: Manage › Categories' lists are never cut (a longer name chosen after another type, a
|
|
2
|
+
list long enough for its scroll bar), a long list scrolls in a short window, and the columns of
|
|
3
|
+
the transactions under them have a few pixels to spare."""
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from conftest import keep
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.fixture(scope="module")
|
|
11
|
+
def qapp():
|
|
12
|
+
from PySide6.QtWidgets import QApplication
|
|
13
|
+
return QApplication.instance() or QApplication([])
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def settle(app):
|
|
17
|
+
for _ in range(6):
|
|
18
|
+
app.processEvents()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_lists_fit_their_text_and_scroll(qapp, db):
|
|
22
|
+
from daftarche.style import get_settings
|
|
23
|
+
from daftarche.tabs.manage import ManageDialog
|
|
24
|
+
from daftarche.tx_list import SHOW_KEY
|
|
25
|
+
db.get_or_create_account("Card")
|
|
26
|
+
db.add_category("Bank", "Income")
|
|
27
|
+
for i in range(25):
|
|
28
|
+
db.add_category(f"A rather long expense category {i}", "Expense")
|
|
29
|
+
db.conn.commit()
|
|
30
|
+
get_settings()._data[SHOW_KEY] = True
|
|
31
|
+
m = keep(ManageDialog(db, lambda: None))
|
|
32
|
+
m.resize(900, 560)
|
|
33
|
+
m.show()
|
|
34
|
+
p = m.cats_panel
|
|
35
|
+
m.tabs.setCurrentWidget(p.parentWidget() if m.tabs.indexOf(p) < 0 else p)
|
|
36
|
+
settle(qapp)
|
|
37
|
+
types = {p.type_table.item(r, 0).text(): r for r in range(p.type_table.rowCount())}
|
|
38
|
+
p.type_table.selectRow(types["Income"])
|
|
39
|
+
settle(qapp)
|
|
40
|
+
p.type_table.selectRow(types["Expense"]) # longer names than the Income ones, and many
|
|
41
|
+
settle(qapp)
|
|
42
|
+
for table in (p.type_table, p.cat_table, p.sub_table):
|
|
43
|
+
columns = sum(table.columnWidth(c) for c in range(table.columnCount()))
|
|
44
|
+
assert table.viewport().width() >= columns, table.objectName()
|
|
45
|
+
assert table.geometry().right() < table.parentWidget().width() + 1 # not cut by its column
|
|
46
|
+
t = p.cat_table
|
|
47
|
+
assert t.verticalScrollBar().maximum() > 0 # a long list in a short window: it scrolls
|
|
48
|
+
assert t.height() < t.verticalHeader().length()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_columns_below_have_room_to_spare(qapp, db):
|
|
52
|
+
from daftarche.tabs.transactions import COL_DATE
|
|
53
|
+
from daftarche.tx_list import SLACK, TransactionList
|
|
54
|
+
db.get_or_create_account("Wallet")
|
|
55
|
+
cat, sub = db.get_transfer_cat_sub(description="x", matched=True)
|
|
56
|
+
db.add_transaction(2023, "August", 21, "Transfer", None, 5000, sub, cat, to_account_name="Wallet")
|
|
57
|
+
db.conn.commit()
|
|
58
|
+
lines = keep(TransactionList(db, lambda: None))
|
|
59
|
+
lines.show_transactions("Wallet", {"type": ["Transfer"]})
|
|
60
|
+
t = lines.tx.table
|
|
61
|
+
need = t.sizeHintForIndex(t.model().index(0, COL_DATE)).width()
|
|
62
|
+
assert t.columnWidth(COL_DATE) >= need + SLACK
|
|
@@ -48,8 +48,9 @@ def test_four_tabs_and_the_go_menu(win):
|
|
|
48
48
|
assert win.tabs.currentWidget() is win.charts_tab
|
|
49
49
|
file_menu = next(a.menu() for a in win.menuBar().actions() if a.text() == "File")
|
|
50
50
|
keys = {a.text(): a.shortcut().toString() for a in file_menu.actions() if a.text()}
|
|
51
|
-
assert keys["Import Statement…"] == "Ctrl+I" and keys["
|
|
52
|
-
assert keys["
|
|
51
|
+
assert keys["Import Statement…"] == "Ctrl+I" and keys["Save Checkpoint"] == "Ctrl+S"
|
|
52
|
+
assert keys["Back Up Database…"] == "Ctrl+Shift+S"
|
|
53
|
+
assert keys["Restore Backup…"] == "" and keys["Revert to a Save…"] == "" # on purpose
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
def test_review_stays_in_transactions(win):
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|