73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
import uuid
|
|
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, Unicode
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, relationship
|
|
|
|
from .meta import Base
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
# if the target of the relationship is in another module
|
|
# that cannot normally be imported at runtime
|
|
from .account import Account
|
|
from .product_group import ProductGroup
|
|
from .stock_keeping_unit import StockKeepingUnit
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = "products"
|
|
|
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
code: int = Column("code", Integer, unique=True)
|
|
name: str = Column("name", Unicode(255), nullable=False, unique=True)
|
|
fraction_units: str = Column("fraction_units", Unicode(255), nullable=False)
|
|
product_group_id: uuid.UUID = Column(
|
|
"product_group_id",
|
|
UUID(as_uuid=True),
|
|
ForeignKey("product_groups.id"),
|
|
nullable=False,
|
|
)
|
|
account_id: uuid.UUID = Column("account_id", UUID(as_uuid=True), ForeignKey("accounts.id"), nullable=False)
|
|
is_active: bool = Column("is_active", Boolean, nullable=False)
|
|
is_fixture: bool = Column("is_fixture", Boolean, nullable=False)
|
|
is_purchased: bool = Column("is_purchased", Boolean, nullable=False)
|
|
is_sold: bool = Column("is_sold", Boolean, nullable=False)
|
|
|
|
skus: List["StockKeepingUnit"] = relationship("StockKeepingUnit", back_populates="product")
|
|
product_group: Mapped["ProductGroup"] = relationship("ProductGroup", back_populates="products")
|
|
account: Mapped["Account"] = relationship("Account", back_populates="products")
|
|
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
fraction_units: str,
|
|
product_group_id: uuid.UUID,
|
|
account_id: uuid.UUID,
|
|
is_active: bool,
|
|
is_purchased: bool,
|
|
is_sold: bool,
|
|
code: Optional[int] = None,
|
|
id_: Optional[uuid.UUID] = None,
|
|
is_fixture: Optional[bool] = False,
|
|
) -> None:
|
|
if code is not None:
|
|
self.code = code
|
|
self.name = name
|
|
self.fraction_units = fraction_units
|
|
self.product_group_id = product_group_id
|
|
self.account_id = account_id
|
|
self.is_active = is_active
|
|
self.is_purchased = is_purchased
|
|
self.is_sold = is_sold
|
|
if id_ is not None:
|
|
self.id = id_
|
|
if is_fixture is not None:
|
|
self.is_fixture = is_fixture
|
|
|
|
@classmethod
|
|
def suspense(cls) -> uuid.UUID:
|
|
return uuid.UUID("aa79a643-9ddc-4790-ac7f-a41f9efb4c15")
|