feat(backend): expense lines (quantity, price before VAT, VAT %) and documents (PDF / photo)

An expense can list what it bought; the lines make its total (net, VAT half up per line), are
replaced on edit ([] removes them) and the total still can't drop below what was paid. Files kept
with an expense: POST/GET/DELETE /api/expenses/{id}/documents[/{doc}], PDF / JPG / PNG / WebP /
HEIC by their bytes, at most 15 MB, under MEDIA_DIR/expenses/<id>/ (removed with the expense).
Migration 0039.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 14:57:58 +02:00
co-authored by Claude Opus 5.5
parent 5915177c82
commit 9297cbcd3b
9 changed files with 361 additions and 5 deletions
+30 -1
View File
@@ -59,11 +59,35 @@ class ExpensePaymentOut(BaseModel):
model_config = {"from_attributes": True}
class ExpenseLineIn(BaseModel):
description: str
quantity: float = 1.0
unit_price: float
vat_rate: float = 0.0
class ExpenseLineOut(ExpenseLineIn):
id: int
net: float
vat: float
total: float
class ExpenseDocumentOut(BaseModel):
id: int
filename: str
content_type: str
size: int
uploaded_at: datetime
uploaded_by_name: Optional[str] = None
class ExpenseCreate(BaseModel):
description: str
category: str
contact_id: Optional[int] = None
total_amount: float
total_amount: Optional[float] = None # left out when the lines make it
lines: Optional[List[ExpenseLineIn]] = None
due_date: Optional[datetime] = None
business_day_id: Optional[int] = None
notes: Optional[str] = None
@@ -80,6 +104,7 @@ class ExpenseUpdate(BaseModel):
category: Optional[str] = None
contact_id: Optional[int] = None
total_amount: Optional[float] = None
lines: Optional[List[ExpenseLineIn]] = None # given: replaces the lines ([] = none)
due_date: Optional[datetime] = None
notes: Optional[str] = None
@@ -107,5 +132,9 @@ class ExpenseOut(BaseModel):
created_at: datetime
notes: Optional[str] = None
payments: List[ExpensePaymentOut] = []
lines: List[ExpenseLineOut] = []
net_amount: Optional[float] = None # from the lines
vat_amount: Optional[float] = None
documents: List[ExpenseDocumentOut] = []
model_config = {"from_attributes": True}