feat: Implement currency management with models, routes, and UI updates; add backfill script for existing records

This commit is contained in:
2025-10-21 10:33:08 +02:00
parent fcea39deb0
commit 672cafa5b9
14 changed files with 478 additions and 10 deletions

View File

@@ -0,0 +1,54 @@
from tests.unit.conftest import client
def test_create_capex_with_currency_code_and_list():
# create scenario first (reuse helper from other tests)
from tests.unit.test_costs import _create_scenario
sid = _create_scenario()
# create with currency_code
payload = {
"scenario_id": sid,
"amount": 500.0,
"description": "Capex with GBP",
"currency_code": "GBP",
}
resp = client.post("/api/costs/capex", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["currency_code"] == "GBP" or data.get(
"currency", {}).get("code") == "GBP"
def test_create_opex_with_currency_id():
from tests.unit.test_costs import _create_scenario
from routes.currencies import list_currencies
sid = _create_scenario()
# fetch currencies to get an id
resp = client.get("/api/currencies/")
assert resp.status_code == 200
currencies = resp.json()
assert len(currencies) > 0
cid = currencies[0]["id"]
payload = {
"scenario_id": sid,
"amount": 120.0,
"description": "Opex with explicit id",
"currency_id": cid,
}
resp = client.post("/api/costs/opex", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["currency_id"] == cid
def test_list_currencies_endpoint():
resp = client.get("/api/currencies/")
assert resp.status_code == 200
data = resp.json()
assert isinstance(data, list)
assert all("id" in c and "code" in c for c in data)