3
from typing import Optional
4
from typing import TYPE_CHECKING
6
from sqlalchemy import Sequence, Uuid, ForeignKey, UniqueConstraint, String
7
from sqlalchemy.dialects.postgresql import ARRAY
8
from sqlalchemy.orm import Mapped, mapped_column
9
from sqlalchemy.orm import relationship
11
from core.db import Base
12
from core.db.mixins import AllMixin
13
from core.db.types import ids
16
from app.basic.uom.models import Uom
19
class ProductCategory(Base, AllMixin):
20
__tablename__ = "product_category"
21
__table_args__ = (UniqueConstraint('external_number', 'company_id', name='_product_category_company_id_uc'),)
22
lsn_seq = Sequence(f'product_category_lsn_seq')
23
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
24
external_number: Mapped[Optional[str]]
25
title: Mapped[str] = mapped_column(index=True)
26
product_category_ids: Mapped[Optional[ids]] = mapped_column(index=True)
28
class ProductType(str, Enum):
29
CONSUMABLE: str = 'consumable'
30
STORABLE: str = 'storable'
33
class Product(Base, AllMixin):
34
__tablename__ = "product"
35
__table_args__ = (UniqueConstraint('external_number', 'company_id', name='_product_company_id_uc'),)
36
lsn_seq = Sequence(f'product_lsn_seq')
37
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, index=True, default=uuid.uuid4)
38
title: Mapped[str] = mapped_column(index=True)
39
description: Mapped[Optional[str]]
40
image_url: Mapped[Optional[str]]
41
external_number: Mapped[Optional[str]]
42
product_type: Mapped[str] = mapped_column(default=ProductType.STORABLE)
43
uom_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("uom.id"), index=True)
44
uom_rel: Mapped['Uom'] = relationship(lazy='selectin')
45
product_category_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("product_category.id"), index=True)
46
barcode_list: Mapped[list[str]] = mapped_column(ARRAY(String), index=True, server_default='{}')