- Backend: FastAPI with email filtering and invoice processing - Database: PostgreSQL models (Invoice, EmailLog, InvoiceDetail, User) - PDF Processing: PyMuPDF for text extraction and tax detection - Excel Export: openpyxl for invoice documentation - Frontend: React/Vite with TypeScript - Docker: Backend container configuration - Documentation: Schema and API docs
128 lines
2.7 KiB
Python
128 lines
2.7 KiB
Python
"""
|
|
C-Stone Invoice Check — Pydantic Schemas
|
|
API Request/Response Definitionen
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import Optional, List, Dict, Any
|
|
from pydantic import BaseModel
|
|
|
|
|
|
# Invoice Schemas
|
|
class InvoiceBase(BaseModel):
|
|
email_id: Optional[str] = None
|
|
email_subject: Optional[str] = None
|
|
email_from: Optional[str] = None
|
|
email_date: Optional[datetime] = None
|
|
|
|
invoice_number: Optional[str] = None
|
|
invoice_date: Optional[datetime] = None
|
|
invoice_amount: Optional[float] = None
|
|
invoice_tax_amount: Optional[float] = None
|
|
invoice_tax_rate: Optional[float] = None
|
|
invoice_tax_type: Optional[str] = None
|
|
|
|
issuer_name: Optional[str] = None
|
|
issuer_address: Optional[str] = None
|
|
|
|
file_path: Optional[str] = None
|
|
file_name: Optional[str] = None
|
|
storage_year: Optional[int] = None
|
|
storage_path: Optional[str] = None
|
|
|
|
processed: bool = False
|
|
processing_error: Optional[str] = None
|
|
confidence_score: Optional[float] = None
|
|
|
|
|
|
class InvoiceCreate(InvoiceBase):
|
|
pass
|
|
|
|
|
|
class InvoiceResponse(InvoiceBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Email Log Schemas
|
|
class EmailLogBase(BaseModel):
|
|
email_id: str
|
|
email_subject: Optional[str] = None
|
|
email_from: Optional[str] = None
|
|
email_date: Optional[datetime] = None
|
|
email_folder: Optional[str] = None
|
|
|
|
matched_keywords: Optional[List[str]] = None
|
|
has_attachment: bool = False
|
|
attachment_type: Optional[str] = None
|
|
|
|
processed: bool = False
|
|
processing_result: Optional[str] = None
|
|
invoice_id: Optional[int] = None
|
|
|
|
|
|
class EmailLogCreate(EmailLogBase):
|
|
pass
|
|
|
|
|
|
class EmailLogResponse(EmailLogBase):
|
|
id: int
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# PDF Scan Response
|
|
class TaxInfo(BaseModel):
|
|
tax_type: str
|
|
tax_rate: Optional[float]
|
|
confidence: float
|
|
found_keyword: Optional[str]
|
|
|
|
|
|
class PDFScanResponse(BaseModel):
|
|
id: Optional[int] = None
|
|
invoice_number: Optional[str] = None
|
|
amount: Optional[float] = None
|
|
issuer: Optional[str] = None
|
|
tax_type: Optional[str] = None
|
|
tax_rate: Optional[float] = None
|
|
pages: int
|
|
error: Optional[str] = None
|
|
|
|
|
|
# Excel Export Response
|
|
class ExportResponse(BaseModel):
|
|
status: str
|
|
file_path: str
|
|
invoice_count: int
|
|
|
|
|
|
# Auth Schemas
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
username: Optional[str] = None
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
username: str
|
|
password: str
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
id: int
|
|
username: str
|
|
is_active: bool
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|