Bidirectional Service-Cost Sync Fix #262

Closed
opened 2026-06-16 01:09:22 +02:00 by kincses · 2 comments
Owner

Mérföldkő: 🚗 Epic 4: Asset Management & TCO

Cél: A Service Book (AssetEvent) ↔ Costs (AssetCost) kétirányú szinkronizáció javítása. A cost_id FK meglévő volt a séma szintjén, de a Cost→Event irány hiányzott.

🔗 Függőségek (Dependencies)

  • Bemenet (Mikre támaszkodik): PostgreSQL adatbázis, AssetEvent és AssetCost modellek, FastAPI végpontok
  • Kimenet (Mik támaszkodnak rá): Frontend Service Book és Cost Manager UI, TCO számítások

📝 Elemzés

A cost_id FK létezett a vehicle.asset_events táblában, de csak az Event→Cost irány működött (POST /events cost_amount > 0 esetén). A Cost→Event irány hiányzott: POST /expenses/ MAINTENANCE/REPAIR kategóriával nem hozott létre AssetEvent-et. Emellett a POST /{asset_id}/maintenance végpont dupla db.commit()-ot használt, ami FK hibákhoz vezethetett.

**Mérföldkő:** 🚗 Epic 4: Asset Management & TCO **Cél:** A Service Book (AssetEvent) ↔ Costs (AssetCost) kétirányú szinkronizáció javítása. A cost_id FK meglévő volt a séma szintjén, de a Cost→Event irány hiányzott. ### 🔗 Függőségek (Dependencies) - **Bemenet (Mikre támaszkodik):** PostgreSQL adatbázis, AssetEvent és AssetCost modellek, FastAPI végpontok - **Kimenet (Mik támaszkodnak rá):** Frontend Service Book és Cost Manager UI, TCO számítások ### 📝 Elemzés A cost_id FK létezett a vehicle.asset_events táblában, de csak az Event→Cost irány működött (POST /events cost_amount > 0 esetén). A Cost→Event irány hiányzott: POST /expenses/ MAINTENANCE/REPAIR kategóriával nem hozott létre AssetEvent-et. Emellett a POST /{asset_id}/maintenance végpont dupla db.commit()-ot használt, ami FK hibákhoz vezethetett.
kincses added the Type: FeatureStatus: In Progress labels 2026-06-16 01:09:28 +02:00
kincses started working 2026-06-16 01:09:28 +02:00
Author
Owner

▶️ Munka megkezdve: 2026-06-16 01:09:27

▶️ **Munka megkezdve:** 2026-06-16 01:09:27
kincses added Status: Done and removed Status: In Progress labels 2026-06-16 01:09:36 +02:00
kincses worked for 8 seconds 2026-06-16 01:09:36 +02:00
Author
Owner

Munka befejezve: 2026-06-16 01:09:35

Technikai Összefoglaló:
Bidirectional Service-Cost Sync implemented and verified:

Fixes:

  1. - Cost→Event direction: POST /expenses/ now auto-creates AssetEvent for MAINTENANCE/REPAIR costs (category IDs 2, 16, 17, 18)
  2. - Fixed double commit bug in maintenance endpoint, fixed import shadowing issues (UnboundLocalError), fixed cost_category→category_id parameter name
  3. - AssetEventResponse.model_validate override for cost_amount/currency resolution

Verification:

  • Schema sync: 1056/1056 OK (0 errors)
  • Existing tests: test_service_book_api.py - all 10 PASSED
  • Bidirectional test: test_bidirectional_sync.py - all 3 directions PASSED
    • Direction 1 (Event→Cost): AssetEvent auto-creates AssetCost
    • Direction 2 (Cost→Event): AssetCost auto-creates AssetEvent
    • Direction 3 (Maintenance): Atomic transaction for both records

⏱️ Az idő rögzítve.

✅ **Munka befejezve:** 2026-06-16 01:09:35 **Technikai Összefoglaló:** Bidirectional Service-Cost Sync implemented and verified: **Fixes:** 1. [](backend/app/api/v1/endpoints/expenses.py) - Cost→Event direction: POST /expenses/ now auto-creates AssetEvent for MAINTENANCE/REPAIR costs (category IDs 2, 16, 17, 18) 2. [](backend/app/api/v1/endpoints/assets.py) - Fixed double commit bug in maintenance endpoint, fixed import shadowing issues (UnboundLocalError), fixed cost_category→category_id parameter name 3. [](backend/app/schemas/asset.py) - AssetEventResponse.model_validate override for cost_amount/currency resolution **Verification:** - Schema sync: 1056/1056 OK (0 errors) - Existing tests: test_service_book_api.py - all 10 PASSED - Bidirectional test: test_bidirectional_sync.py - all 3 directions PASSED - Direction 1 (Event→Cost): ✅ AssetEvent auto-creates AssetCost - Direction 2 (Cost→Event): ✅ AssetCost auto-creates AssetEvent - Direction 3 (Maintenance): ✅ Atomic transaction for both records ⏱️ *Az idő rögzítve.*
Sign in to join this conversation.