Files
erp-nutzfahrzeuge/backend/app/models/datev_export.py
T

49 lines
1.7 KiB
Python
Raw Normal View History

"""SQLAlchemy model for DATEV export records."""
import uuid
from datetime import date, datetime
from decimal import Decimal
from sqlalchemy import Date, DateTime, Numeric, String, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class DATEVExport(Base):
"""DATEV export record tracking CSV exports for accounting."""
__tablename__ = "datev_exports"
id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
)
start_date: Mapped[date] = mapped_column(Date, nullable=False)
end_date: Mapped[date] = mapped_column(Date, nullable=False)
file_path: Mapped[str | None] = mapped_column(String(500), nullable=True)
total_amount: Mapped[Decimal] = mapped_column(
Numeric(14, 2), nullable=False, default=0
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
def __repr__(self) -> str:
return f"<DATEVExport id={self.id} start={self.start_date} end={self.end_date}>"
def to_dict(self) -> dict:
"""Serialize DATEV export for API responses."""
return {
"id": str(self.id),
"start_date": self.start_date.isoformat() if self.start_date else None,
"end_date": self.end_date.isoformat() if self.end_date else None,
"file_path": self.file_path,
"total_amount": (
float(self.total_amount) if self.total_amount is not None else None
),
"created_at": self.created_at.isoformat() if self.created_at else None,
}