pratikbackend / app /models /bill_sequence.py
Antaram's picture
Upload 96 files
7647b38 verified
Raw
History Blame Contribute Delete
1.57 kB
"""
Bill Number Sequence Model
Manages bill numbering with batch system (A1-A500, B1-B500, etc.)
"""
from sqlalchemy import String, Integer, Boolean, DateTime, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
from typing import Optional
import uuid
from app.core.database import Base
class BillNumberSequence(Base):
"""
Bill number sequence tracking
Format: {PREFIX}{YEAR}{BATCH}{NUMBER}
Example: A2025A001, A2025A500, A2025B001
"""
__tablename__ = "bill_number_sequences"
__table_args__ = (
UniqueConstraint('bill_type', 'year', 'batch', name='uq_bill_sequence'),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
bill_type: Mapped[str] = mapped_column(String(20), nullable=False) # 'awaak', 'jawaak', 'patti_awaak', 'patti_jawaak'
year: Mapped[int] = mapped_column(Integer, nullable=False)
batch: Mapped[str] = mapped_column(String(1), nullable=False) # 'A' to 'Z'
current_number: Mapped[int] = mapped_column(Integer, default=0) # 0 to 500
is_full: Mapped[bool] = mapped_column(Boolean, default=False) # True when reaches 500
created_at: Mapped[DateTime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[DateTime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
def __repr__(self) -> str:
return f"<BillNumberSequence(type={self.bill_type}, year={self.year}, batch={self.batch}, num={self.current_number})>"