feat: Import-Vorlage richtet sich nach dem gewaehlten Konto

Beim Kontowechsel musste man die Vorlage jedes Mal neu waehlen – und las
im schlimmsten Fall den Revolut-Auszug mit der Raiffeisen-Vorlage ein
(genau das steht im Verlauf).

Eigene Vorlagen standen schon als template_id im Verlauf; Bank-Vorlagen
sind fest im Code und hinterliessen nichts. Der Verlauf merkt sich deshalb
jetzt auch deren Namen (Migration 0014). Die Oberflaeche waehlt beim
Kontowechsel, womit zuletzt in dieses Konto importiert wurde.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Guido
2026-08-21 20:44:50 +02:00
co-authored by Claude Opus 5
parent 78835d1e40
commit 3a44509e77
7 changed files with 79 additions and 5 deletions
+22 -2
View File
@@ -58,6 +58,7 @@ export default function Import() {
const [file, setFile] = useState(null);
const [config, setConfig] = useState(defaultConfig());
const [raw, setRaw] = useState(null);
const [quelle, setQuelle] = useState(""); // "preset:i" | "tpl:id" | ""
const [rows, setRows] = useState(null);
const [recon, setRecon] = useState(null);
const [docText, setDocText] = useState("");
@@ -100,6 +101,7 @@ export default function Import() {
}
// Ein zusammengeführtes Vorlagen-Dropdown: Werte typ-getaggt "preset:i" / "tpl:id".
function applySource(value) {
setQuelle(value || "");
if (!value) return;
const [kind, id] = value.split(":");
if (kind === "preset") {
@@ -111,6 +113,22 @@ export default function Import() {
}
}
// Beim Kontowechsel die Einstellung vorschlagen, mit der zuletzt in DIESES
// Konto importiert wurde. Ohne das waehlt man jedes Mal neu – und liest im
// schlimmsten Fall den Revolut-Auszug mit der Raiffeisen-Vorlage ein.
useEffect(() => {
if (!accountId || !batches.length) return;
const letzter = batches.find(
(b) => String(b.account_id) === String(accountId) && (b.template_id || b.preset));
if (!letzter) return;
if (letzter.template_id && templates.some((x) => x.id === letzter.template_id)) {
applySource(`tpl:${letzter.template_id}`);
return;
}
const i = presets.findIndex((p) => p.name === letzter.preset);
if (i >= 0) applySource(`preset:${i}`);
}, [accountId, batches, templates, presets]);
function baseForm() {
const fd = new FormData();
fd.append("file", file);
@@ -168,9 +186,11 @@ export default function Import() {
async function commit() {
setBusy(true);
try {
const [art, id] = quelle.split(":");
const batch = await api.importCommit({
account_id: Number(accountId),
template_id: null,
template_id: art === "tpl" ? Number(id) : null,
preset: art === "preset" ? presets[Number(id)]?.name || null : null,
filename: file?.name || "",
rows,
});
@@ -409,7 +429,7 @@ export default function Import() {
<div className="row" style={{ display: mode === "csv" ? undefined : "none" }}>
<label className="grow">
<span>{t("import.templateAny")}</span>
<select defaultValue="" onChange={(e) => applySource(e.target.value)}>
<select value={quelle} onChange={(e) => applySource(e.target.value)}>
<option value="">{t("import.templateManual")}</option>
{presets.length > 0 && (
<optgroup label={t("import.presetGroup")}>