Files
celtic-life-science/app/stockists/models.py
Shubhankar45 0d30c58bf0 Server backup 2026-11-07 of uncommitted work in projects/pharma-web-celtic
Snapshot of the working tree on srv1071960 (branch main), taken during
server cleanup. .env files, node_modules, builds, logs and media were excluded.
2026-11-07 05:43:12 +00:00

47 lines
1.7 KiB
Python

"""Stockist master data."""
import uuid
from sqlalchemy import Boolean, ForeignKey, String, UniqueConstraint
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.common.enums import MasterApproval
from app.database.base import Base, TimestampMixin, UUIDMixin
class Stockist(Base, UUIDMixin, TimestampMixin):
__tablename__ = "stockist"
__table_args__ = (
UniqueConstraint(
"headquarters_id", "name", "address", name="uq_stockist_hq_name_address"
),
)
headquarters_id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("headquarters.id", ondelete="RESTRICT"), nullable=False
)
name: Mapped[str] = mapped_column(String(200), nullable=False)
address: Mapped[str] = mapped_column(String(500), nullable=False)
contact_number: Mapped[str | None] = mapped_column(String(20))
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
approval_status: Mapped[str] = mapped_column(
String(10), default=MasterApproval.APPROVED.value, server_default=MasterApproval.APPROVED.value, nullable=False
)
requested_by_user_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("user.id", ondelete="SET NULL")
)
rejection_reason: Mapped[str | None] = mapped_column(String(500))
requested_by: Mapped["User | None"] = relationship( # noqa: F821
lazy="selectin", foreign_keys=[requested_by_user_id]
)
@property
def requested_by_name(self) -> str | None:
return self.requested_by.full_name if self.requested_by else None
@property
def shop_address(self) -> str:
return self.address