From c7e4b68dfb2687d0f59fef25a2282a8494f84178 Mon Sep 17 00:00:00 2001 From: Mathias Scheider Date: Fri, 16 Oct 2026 12:28:57 +0200 Subject: [PATCH] Fix comdirect CSV reader for neu group header rows --- src/ingest/comdirect.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ingest/comdirect.py b/src/ingest/comdirect.py index d9e764e..361ec6f 100644 --- a/src/ingest/comdirect.py +++ b/src/ingest/comdirect.py @@ -73,6 +73,10 @@ def _reader_raw_comdirect(path: Path) -> CsV2DictMulti: account_name: str | None = None header: list[str] = [] result: CsV2DictMulti = {} + # Comdirect groups "new" transactions (marked with "neu") under a header + # line that carries only their Buchungstag; remember it until the next + # transaction row for the same account. + pending_book_date: dict[str, str] = {} for line in lines: if expect_next == EXPECT_LINE.ACCOUNT_NAME: matches = re.findall(PATTERN_ACCOUNT_NAME, line) @@ -91,13 +95,18 @@ def _reader_raw_comdirect(path: Path) -> CsV2DictMulti: expect_next = EXPECT_LINE.DATA elif expect_next == EXPECT_LINE.DATA: data = re.findall(PATTERN_DATA, line) - if data: - assert account_name is not None - result[account_name].append( - {column: value for column, value in zip(header, data)} - ) - else: + if not data: expect_next = EXPECT_LINE.ACCOUNT_NAME + elif len(data) == 1: + # Group header line (single Buchungstag for the "neu" rows below). + assert account_name is not None + pending_book_date[account_name] = data[0] + else: + assert account_name is not None + row = {column: value for column, value in zip(header, data)} + if data[0] == "neu" and account_name in pending_book_date: + row["Buchungstag"] = pending_book_date.pop(account_name) + result[account_name].append(row) else: expect_next = EXPECT_LINE.ACCOUNT_NAME return result