Files
leocrm/app/models/sequence.py
T

31 lines
1.1 KiB
Python
Raw Normal View History

2026-07-04 00:24:16 +00:00
"""Sequence model — document numbering / Nummernkreise."""
from __future__ import annotations
import uuid
from datetime import datetime
from sqlalchemy import DateTime, Index, Integer, String
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column
from app.core.db import Base, TenantMixin
class Sequence(Base, TenantMixin):
"""Sequence entity for document numbering (e.g. invoice RE-2026-0001)."""
__tablename__ = "sequences"
__table_args__ = (
Index("ix_sequences_tenant_name", "tenant_id", "name"),
)
id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)
name: Mapped[str] = mapped_column(String(100), nullable=False)
prefix: Mapped[str] = mapped_column(String(20), nullable=False, default="")
next_number: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
padding: Mapped[int] = mapped_column(Integer, nullable=False, default=4)
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)