feat: barcode templates
This commit is contained in:
@ -1,6 +1,16 @@
|
||||
from .deal_product import DealProduct as DealProduct, DealProductService as DealProductService
|
||||
from .deal_service import (
|
||||
DealService as DealService,
|
||||
from .barcode import (
|
||||
ProductBarcode as ProductBarcode,
|
||||
ProductBarcodeImage as ProductBarcodeImage,
|
||||
)
|
||||
from .barcode_template import (
|
||||
BarcodeTemplateAttribute as BarcodeTemplateAttribute,
|
||||
BarcodeTemplateSize as BarcodeTemplateSize,
|
||||
BarcodeTemplate as BarcodeTemplate,
|
||||
)
|
||||
from .deal_product import (
|
||||
DealProduct as DealProduct,
|
||||
DealProductService as DealProductService,
|
||||
)
|
||||
from .deal_service import DealService as DealService
|
||||
from .product import Product as Product
|
||||
from .service import Service as Service, ServiceCategory as ServiceCategory
|
||||
|
||||
36
modules/fulfillment_base/models/barcode.py
Normal file
36
modules/fulfillment_base/models/barcode.py
Normal file
@ -0,0 +1,36 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models.base import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from modules.fulfillment_base.models import Product
|
||||
|
||||
|
||||
class ProductBarcode(BaseModel):
|
||||
__tablename__ = "fulfillment_base_product_barcodes"
|
||||
|
||||
product_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("fulfillment_base_products.id"),
|
||||
primary_key=True,
|
||||
)
|
||||
product: Mapped["Product"] = relationship(back_populates="barcodes")
|
||||
|
||||
barcode: Mapped[str] = mapped_column(
|
||||
primary_key=True, index=True, comment="ШК товара"
|
||||
)
|
||||
|
||||
|
||||
class ProductBarcodeImage(BaseModel):
|
||||
__tablename__ = "fulfillment_base_product_barcode_images"
|
||||
|
||||
product_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("fulfillment_base_products.id"),
|
||||
primary_key=True,
|
||||
comment="ID товара",
|
||||
)
|
||||
product: Mapped["Product"] = relationship(back_populates="barcode_image")
|
||||
|
||||
filename: Mapped[str] = mapped_column()
|
||||
42
modules/fulfillment_base/models/barcode_template.py
Normal file
42
modules/fulfillment_base/models/barcode_template.py
Normal file
@ -0,0 +1,42 @@
|
||||
from sqlalchemy import ForeignKey, Table, Column
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models.base import BaseModel
|
||||
from models.mixins import IdMixin, SoftDeleteMixin
|
||||
|
||||
barcode_template_attribute_link = Table(
|
||||
"barcode_template_attribute_links",
|
||||
BaseModel.metadata,
|
||||
Column("barcode_template_id", ForeignKey("barcode_templates.id")),
|
||||
Column("attribute_id", ForeignKey("barcode_template_attributes.id")),
|
||||
)
|
||||
|
||||
|
||||
class BarcodeTemplateAttribute(BaseModel, IdMixin):
|
||||
__tablename__ = "barcode_template_attributes"
|
||||
|
||||
key: Mapped[str] = mapped_column(index=True, comment="Ключ атрибута")
|
||||
name: Mapped[str] = mapped_column(index=True, comment="Метка атрибута")
|
||||
|
||||
|
||||
class BarcodeTemplateSize(BaseModel, IdMixin):
|
||||
__tablename__ = "barcode_template_sizes"
|
||||
|
||||
name: Mapped[str] = mapped_column(index=True, comment="Название размера")
|
||||
width: Mapped[int] = mapped_column(comment="Ширина в мм")
|
||||
height: Mapped[int] = mapped_column(comment="Высота в мм")
|
||||
|
||||
|
||||
class BarcodeTemplate(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
__tablename__ = "barcode_templates"
|
||||
|
||||
name: Mapped[str] = mapped_column(index=True, comment="Название шаблона")
|
||||
attributes: Mapped[list["BarcodeTemplateAttribute"]] = relationship(
|
||||
secondary=barcode_template_attribute_link,
|
||||
lazy="selectin",
|
||||
)
|
||||
|
||||
is_default: Mapped[bool] = mapped_column(default=False, comment="По умолчанию")
|
||||
|
||||
size_id: Mapped[int] = mapped_column(ForeignKey("barcode_template_sizes.id"))
|
||||
size: Mapped["BarcodeTemplateSize"] = relationship(lazy="joined")
|
||||
@ -1,8 +1,15 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models.base import BaseModel
|
||||
from models.mixins import IdMixin, SoftDeleteMixin
|
||||
from modules.fulfillment_base.models import (
|
||||
ProductBarcode,
|
||||
BarcodeTemplate,
|
||||
ProductBarcodeImage,
|
||||
)
|
||||
|
||||
|
||||
class Product(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
@ -28,6 +35,22 @@ class Product(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
barcodes: Mapped[list["ProductBarcode"]] = relationship(
|
||||
back_populates="product",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
barcode_template_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey("barcode_templates.id")
|
||||
)
|
||||
barcode_template: Mapped["BarcodeTemplate"] = relationship(lazy="joined")
|
||||
|
||||
barcode_image: Mapped["ProductBarcodeImage"] = relationship(
|
||||
back_populates="product",
|
||||
lazy="joined",
|
||||
uselist=False,
|
||||
)
|
||||
|
||||
|
||||
class ProductImage(BaseModel, IdMixin):
|
||||
__tablename__ = "fulfillment_base_product_images"
|
||||
|
||||
Reference in New Issue
Block a user