mitlist/be/app/schemas/financials.py
mohamad d6c5e6fcfd chore: Remove package-lock.json and enhance financials API with user summaries
This commit includes the following changes:

- Deleted the `package-lock.json` file to streamline dependency management.
- Updated the `financials.py` endpoint to return a comprehensive user financial summary, including net balance, total group spending, debts, and credits.
- Enhanced the `expense.py` CRUD operations to handle enum values and improve error handling during expense deletion.
- Introduced new schemas in `financials.py` for user financial summaries and debt/credit tracking.
- Refactored the costs service to improve group balance summary calculations.

These changes aim to improve the application's financial tracking capabilities and maintain cleaner dependency management.
2025-06-28 21:37:26 +02:00

38 lines
1.0 KiB
Python

from pydantic import BaseModel, Field
from typing import Union, List
from .expense import ExpensePublic, SettlementPublic
from decimal import Decimal
class FinancialActivityResponse(BaseModel):
activities: List[Union[ExpensePublic, SettlementPublic]]
class Config:
orm_mode = True
class SummaryUser(BaseModel):
"""Lightweight representation of a user for summary responses."""
id: int
name: str
class Config:
orm_mode = True
class DebtCredit(BaseModel):
"""Represents a debt or credit entry in the user financial summary."""
user: SummaryUser
amount: float
class Config:
orm_mode = True
class UserFinancialSummary(BaseModel):
"""Aggregated financial summary for the authenticated user across all groups."""
net_balance: float = 0.0
total_group_spending: float = 0.0
debts: List[DebtCredit] = Field(default_factory=list)
credits: List[DebtCredit] = Field(default_factory=list)
currency: str = "USD"
class Config:
orm_mode = True