import uuid from decimal import Decimal from typing import TYPE_CHECKING, List from sqlalchemy import Boolean, ForeignKey, Integer, Numeric, Unicode, text from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg if TYPE_CHECKING: from .inventory import Inventory from .regime import Regime from .sale_category import SaleCategory @reg.mapped_as_dataclass(unsafe_hash=True) class Tax: __tablename__ = "taxes" id: Mapped[uuid.UUID] = mapped_column( "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 ) name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) rate: Mapped[Decimal] = mapped_column("rate", Numeric(precision=15, scale=5), nullable=False) regime_id: Mapped[int] = mapped_column("regime_id", Integer, ForeignKey("regimes.id"), nullable=False) is_fixture: Mapped[bool] = mapped_column("is_fixture", Boolean, nullable=False) sale_categories: Mapped[List["SaleCategory"]] = relationship(back_populates="tax") inventories: Mapped[List["Inventory"]] = relationship(back_populates="tax") regime: Mapped["Regime"] = relationship(back_populates="taxes") def __init__(self, name=None, rate=None, regime_id=None, is_fixture=False, id_=None): self.name = name self.rate = rate self.regime_id = regime_id self.is_fixture = is_fixture self.id = id_