Fix date parsing for image import to handle various date formats

This commit is contained in:
Iyeoluwa Akinrinola
2025-07-03 00:44:01 +01:00
parent e81745b638
commit a202abf5c0
2 changed files with 55 additions and 4 deletions
+8 -3
View File
@@ -200,11 +200,16 @@ async def import_transactions_from_image(file: UploadFile = File(...)):
# Generate unique ID
txn_id = f"img_{file.filename}_{idx+1}"
# Parse date
txn_date = txn.get("date", "")
if not txn_date:
# Parse date - handle various formats
txn_date_raw = txn.get("date", "")
if not txn_date_raw:
raise ValueError("No date found in transaction")
# Convert date to YYYY-MM-DD format
txn_date = document_processor._parse_date_to_iso(txn_date_raw)
if not txn_date:
raise ValueError(f"Could not parse date: {txn_date_raw}")
# Parse amount
amount_str = str(txn.get("amount", "0"))
amount = float(amount_str.replace('$', '').replace(',', '').strip())