Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

fix: support QIF files from Microsoft Money (encoding fallback + date formats)

Tássio Noronhafb13407e8375
diff --git a/backend/app/api/import_transactions.py b/backend/app/api/import_transactions.py
index 3bd9e7e9..91166122 100644
--- a/backend/app/api/import_transactions.py
+++ b/backend/app/api/import_transactions.py
@@ -1,3 +1,4 @@
+import logging
from typing import Optional
from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile, status
@@ -10,6 +11,8 @@ from app.schemas.transaction import TransactionImportPreview, TransactionImportR
from app.services import import_service
from app.services import account_service
+logger = logging.getLogger(__name__)
+
router = APIRouter(prefix="/api/transactions", tags=["import"])
@@ -25,6 +28,11 @@ async def preview_import(
content = await file.read()
filename = file.filename or ""
+ logger.info(
+ "Import preview requested: filename=%s, size=%d bytes, content_type=%s",
+ filename, len(content), file.content_type,
+ )
+
try:
if filename.lower().endswith('.ofx') or filename.lower().endswith('.qfx'):
transactions = import_service.parse_ofx(content)
@@ -61,11 +69,23 @@ async def preview_import(
transactions = import_service.parse_csv(content)
detected_format = "csv"
except Exception as e:
+ logger.error(
+ "Failed to parse import file: filename=%s, size=%d bytes, "
+ "content_type=%s, first_100_bytes=%r, error=%s",
+ filename, len(content), file.content_type,
+ content[:100], e,
+ exc_info=True,
+ )
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Failed to parse file: {str(e)}",
)
+ logger.info(
+ "Import preview parsed: filename=%s, format=%s, transactions=%d",
+ filename, detected_format, len(transactions),
+ )
+
return TransactionImportPreview(transactions=transactions, detected_format=detected_format)
diff --git a/backend/app/services/import_service.py b/backend/app/services/import_service.py
index 6ebdfc04..22e4c8ca 100644
--- a/backend/app/services/import_service.py
+++ b/backend/app/services/import_service.py
@@ -38,7 +38,11 @@ def parse_ofx(content: bytes) -> list[TransactionBase]:
def parse_qif(content: bytes) -> list[TransactionBase]:
"""Parse QIF file content and return transactions."""
- text = content.decode('utf-8-sig')
+ # Try UTF-8 first, fall back to Latin-1 for legacy software (e.g. Microsoft Money)
+ try:
+ text = content.decode('utf-8-sig')
+ except UnicodeDecodeError:
+ text = content.decode('latin-1')
transactions = []
# Split into transaction blocks by "^"
@@ -59,8 +63,12 @@ def parse_qif(content: bytes) -> list[TransactionBase]:
continue
tag, value = line[0], line[1:]
if tag == 'D':
- # Try common date formats
- for fmt in ['%m/%d/%Y', '%d/%m/%Y', '%Y-%m-%d', "%m/%d'%Y"]:
+ # Try common date formats (including 2-digit year variants)
+ for fmt in [
+ '%m/%d/%Y', '%d/%m/%Y', '%Y-%m-%d',
+ "%m/%d'%Y", "%m/%d'%y",
+ '%m/%d/%y', '%d/%m/%y',
+ ]:
try:
txn_date = datetime.strptime(value.strip(), fmt).date()
break
diff --git a/backend/tests/test_import_service.py b/backend/tests/test_import_service.py
index 56a70a1d..9497129f 100644
--- a/backend/tests/test_import_service.py
+++ b/backend/tests/test_import_service.py
@@ -310,6 +310,45 @@ class TestParseQif:
assert len(transactions) == 1
assert transactions[0].amount == Decimal("1250.00")
+ def test_parse_qif_latin1_encoding(self):
+ """QIF files from legacy software (e.g. Microsoft Money) using Latin-1 encoding."""
+ qif_content = (
+ "!Type:Bank\n"
+ "D01/15/2026\n"
+ "T-75.00\n"
+ "PCaf\u00e9 Fran\u00e7ais\n"
+ "^\n"
+ )
+ transactions = parse_qif(qif_content.encode("latin-1"))
+ assert len(transactions) == 1
+ assert transactions[0].description == "Caf\u00e9 Fran\u00e7ais"
+ assert transactions[0].amount == Decimal("75.00")
+ assert transactions[0].type == "debit"
+
+ def test_parse_qif_two_digit_year(self):
+ """QIF with 2-digit year date formats (common in Microsoft Money)."""
+ qif_content = (
+ "D01/15/26\n"
+ "T-50.00\n"
+ "PTest\n"
+ "^\n"
+ )
+ transactions = parse_qif(qif_content.encode("utf-8"))
+ assert len(transactions) == 1
+ assert transactions[0].date == date(2026, 1, 15)
+
+ def test_parse_qif_apostrophe_two_digit_year(self):
+ """QIF with apostrophe separator and 2-digit year (Microsoft Money format)."""
+ qif_content = (
+ "D01/15'26\n"
+ "T-100.00\n"
+ "PTest\n"
+ "^\n"
+ )
+ transactions = parse_qif(qif_content.encode("utf-8"))
+ assert len(transactions) == 1
+ assert transactions[0].date == date(2026, 1, 15)
+
class TestParseCamt:
"""Tests for the parse_camt function (ISO 20022 XML)."""