diff --git a/app/main.py b/app/main.py index 377b455..32761d5 100644 --- a/app/main.py +++ b/app/main.py @@ -365,11 +365,11 @@ async def upload_multiple_documents( @app.post( - "/process", + "/process/{file_id}", response_model=DocumentProcessResponse, tags=["Document Processing"], ) -async def process_document(request: DocumentProcessRequest, db: db_dependency): +async def process_document(file_id: str, request: DocumentProcessRequest, db: db_dependency): """ Process a previously uploaded document to extract receipt information. @@ -381,10 +381,10 @@ async def process_document(request: DocumentProcessRequest, db: db_dependency): """ try: # Get file info from database - db_uploaded_file = get_uploaded_file_from_db(db, request.file_id) + db_uploaded_file = get_uploaded_file_from_db(db, file_id) if not db_uploaded_file: raise HTTPException( - status_code=404, detail=f"File {request.file_id} not found" + status_code=404, detail=f"File {file_id} not found" ) # Process the file using the stored file path @@ -406,8 +406,8 @@ async def process_document(request: DocumentProcessRequest, db: db_dependency): # Create database receipt object db_receipt = DBReceipt( - receipt_id=f"receipt_{request.file_id}", - file_id=request.file_id, + receipt_id=f"receipt_{file_id}", + file_id=file_id, amount=receipt_data.get("total_amount", 0.0), date=receipt_date, vendor=receipt_data.get("vendor", ""), @@ -433,7 +433,7 @@ async def process_document(request: DocumentProcessRequest, db: db_dependency): db.commit() return DocumentProcessResponse( - file_id=request.file_id, + file_id=file_id, receipt_id=db_receipt.receipt_id, extraction_success=receipt_data.get("extraction_success", False), vendor=receipt_data.get("vendor", ""), @@ -579,8 +579,8 @@ async def match_specific_receipts(request: MatchSpecificRequest, db: db_dependen for result in matching_results: # Get final tax amount from LLM analysis if available, otherwise use receipt's stated tax final_tax = result.receipt.tax - if result.tax_analysis and "final_tax_amount" in result.tax_analysis: - final_tax = result.tax_analysis["final_tax_amount"] + # if result.tax_analysis and "final_tax_amount" in result.tax_analysis: + # final_tax = result.tax_analysis["final_tax_amount"] match_response = MatchResponse( receipt_id=result.receipt.id, diff --git a/app/schemas.py b/app/schemas.py index 1e3e5f9..61a438e 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -161,7 +161,7 @@ class DocumentUploadResponse(BaseModel): class DocumentProcessRequest(BaseModel): - file_id: str + file_id: Optional[str] = None user_location: Optional[str] = ( None # Format: "State/Province, Country" (e.g., "Ontario, Canada") ) diff --git a/app/services/document_processor.py b/app/services/document_processor.py index 7473509..dbf1e27 100644 --- a/app/services/document_processor.py +++ b/app/services/document_processor.py @@ -108,6 +108,7 @@ class DocumentProcessor: * For other locations, estimate based on typical rates - Store calculated tax in "calculated_tax" field (set to null if tax clearly shown) - If tax is clearly shown on receipt, use that value for tax_amount and set calculated_tax to null + - If tax is clearly shown on the receipt as 0%, set tax_amount to 0 and calculated_tax to null DEPRECIATION RULES: - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) diff --git a/app/services/matching_engine.py b/app/services/matching_engine.py index 4acba49..9f86fe0 100644 --- a/app/services/matching_engine.py +++ b/app/services/matching_engine.py @@ -51,22 +51,22 @@ class MatchingEngine: enhanced_matches = self._apply_manual_tax_analysis( ai_matches, user_location ) - else: - # Use LLM-based tax analysis in a SINGLE batch call - try: - enhanced_matches = ( - self.llm_tax_analyzer.analyze_and_apply_tax_rules_batch( - ai_matches, user_location - ) - ) - except Exception as e: - # If batch LLM analysis fails, log it and continue with matches as-is - import logging + # else: + # # Use LLM-based tax analysis in a SINGLE batch call + # try: + # enhanced_matches = ( + # self.llm_tax_analyzer.analyze_and_apply_tax_rules_batch( + # ai_matches, user_location + # ) + # ) + # except Exception as e: + # # If batch LLM analysis fails, log it and continue with matches as-is + # import logging - logging.error(f"Batch LLM tax analysis failed: {str(e)}") - for match in ai_matches: - match.match_reason += " (Note: Advanced tax analysis unavailable)" - enhanced_matches = ai_matches + # logging.error(f"Batch LLM tax analysis failed: {str(e)}") + # for match in ai_matches: + # match.match_reason += " (Note: Advanced tax analysis unavailable)" + # enhanced_matches = ai_matches return enhanced_matches