Skip to content

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

fix: persist manual transaction external IDs (#838)

z0diak8ca6ba6b0a58
diff --git a/backend/app/services/transaction_service.py b/backend/app/services/transaction_service.py
index f67635c3..642d1518 100644
--- a/backend/app/services/transaction_service.py
+++ b/backend/app/services/transaction_service.py
@@ -715,6 +715,7 @@ async def create_transaction(
account_id=data.account_id,
category_id=data.category_id, # use provided category if given
payee_id=data.payee_id,
+ external_id=data.external_id,
description=data.description,
amount=data.amount,
currency=currency,
diff --git a/backend/tests/test_transaction_service.py b/backend/tests/test_transaction_service.py
index 8b3f00c4..a11db395 100644
--- a/backend/tests/test_transaction_service.py
+++ b/backend/tests/test_transaction_service.py
@@ -65,6 +65,7 @@ async def test_create_transaction_manual(
type="debit",
account_id=txn_account.id,
category_id=test_categories[0].id,
+ external_id="client-tx-service-001",
)
txn = await create_transaction(session, test_workspace.id, test_user.id, data)
@@ -73,6 +74,7 @@ async def test_create_transaction_manual(
assert txn.source == "manual"
assert txn.status == "posted"
assert txn.category_id == test_categories[0].id
+ assert txn.external_id == "client-tx-service-001"
@pytest.mark.asyncio
diff --git a/backend/tests/test_transactions_api.py b/backend/tests/test_transactions_api.py
index c25f3c18..0e3eb953 100644
--- a/backend/tests/test_transactions_api.py
+++ b/backend/tests/test_transactions_api.py
@@ -370,6 +370,43 @@ async def test_create_transaction(
assert data["description"] == "Almoço restaurante"
assert data["source"] == "manual"
assert data["category_id"] == str(test_categories[0].id)
+ assert data["external_id"] is None
+
+
+async def test_create_transaction_persists_external_id(
+ client: AsyncClient, auth_headers, test_account: Account, test_categories: list[Category]
+):
+ response = await client.post(
+ "/api/transactions",
+ headers=auth_headers,
+ json={
+ "account_id": str(test_account.id),
+ "category_id": str(test_categories[0].id),
+ "description": "External ID transaction",
+ "amount": "32.50",
+ "date": "2026-02-20",
+ "type": "debit",
+ "external_id": "client-tx-api-001",
+ },
+ )
+ assert response.status_code == 201
+ created = response.json()
+ assert created["external_id"] == "client-tx-api-001"
+
+ transaction_id = created["id"]
+ response = await client.get(
+ f"/api/transactions/{transaction_id}", headers=auth_headers
+ )
+ assert response.status_code == 200
+ assert response.json()["external_id"] == "client-tx-api-001"
+
+ response = await client.get(
+ f"/api/transactions?account_id={test_account.id}", headers=auth_headers
+ )
+ assert response.status_code == 200
+ listed = next(item for item in response.json()["items"] if item["id"] == transaction_id)
+ assert listed["external_id"] == "client-tx-api-001"
@pytest.mark.asyncio