Fix date parsing for image import to handle various date formats
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user