mirror of
https://git.hiabuto.net/C3MA/CCMA.git
synced 2026-08-25 15:05:18 +02:00
Remember the last-used GnuCash account per file
AppConfig now keeps a gnucash_last_accounts map (file path -> account guid). When the import dialog opens a file it already knows, it auto-selects whichever account was picked last time for that specific file instead of always defaulting to the first one alphabetically; picking a different account updates and persists the mapping right away. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
745e634a8b
commit
42cde2a0c8
@@ -210,7 +210,7 @@ class GnuCashImportDialog(tk.Toplevel):
|
||||
}
|
||||
self.account_combo.configure(values=list(self.account_by_label))
|
||||
if self.account_by_label and self.account_var.get() not in self.account_by_label:
|
||||
self.account_var.set(next(iter(self.account_by_label)))
|
||||
self.account_var.set(self._preferred_account_label() or next(iter(self.account_by_label)))
|
||||
self.selected_guids.clear()
|
||||
if self.account_var.get():
|
||||
self._account_selected()
|
||||
@@ -221,6 +221,27 @@ class GnuCashImportDialog(tk.Toplevel):
|
||||
self.config.gnucash_path = path_text
|
||||
self.config.save()
|
||||
|
||||
def _current_file_key(self) -> str | None:
|
||||
path_text = self.file_var.get().strip()
|
||||
if not path_text:
|
||||
return None
|
||||
path = Path(path_text).expanduser()
|
||||
if not path.is_file():
|
||||
return None
|
||||
return str(path.resolve())
|
||||
|
||||
def _preferred_account_label(self) -> str | None:
|
||||
file_key = self._current_file_key()
|
||||
if file_key is None:
|
||||
return None
|
||||
last_guid = self.config.gnucash_last_accounts.get(file_key)
|
||||
if not last_guid:
|
||||
return None
|
||||
return next(
|
||||
(label for label, account in self.account_by_label.items() if account.guid == last_guid),
|
||||
None,
|
||||
)
|
||||
|
||||
def _account_selected(self) -> None:
|
||||
account = self.account_by_label.get(self.account_var.get())
|
||||
if account is None:
|
||||
@@ -236,6 +257,10 @@ class GnuCashImportDialog(tk.Toplevel):
|
||||
self.transactions = [item for item in all_transactions if item.amount > 0]
|
||||
self.selected_guids.clear()
|
||||
self._render_transactions()
|
||||
file_key = self._current_file_key()
|
||||
if file_key is not None and self.config.gnucash_last_accounts.get(file_key) != account.guid:
|
||||
self.config.gnucash_last_accounts[file_key] = account.guid
|
||||
self.config.save()
|
||||
|
||||
def _filtered_transactions(self) -> list[GnuCashTransaction]:
|
||||
needle = self.description_filter_var.get().strip().casefold()
|
||||
|
||||
Reference in New Issue
Block a user