feat: modules, products, services, services kits
This commit is contained in:
6
modules/fulfillment_base/models/__init__.py
Normal file
6
modules/fulfillment_base/models/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
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
|
||||
60
modules/fulfillment_base/models/deal_product.py
Normal file
60
modules/fulfillment_base/models/deal_product.py
Normal file
@ -0,0 +1,60 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey, ForeignKeyConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models.base import BaseModel
|
||||
from models.mixins import PriceMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Deal, Service, Product
|
||||
|
||||
|
||||
class DealProduct(BaseModel):
|
||||
__tablename__ = "fulfillment_base_deal_products"
|
||||
|
||||
deal_id: Mapped[int] = mapped_column(ForeignKey("deals.id"), primary_key=True)
|
||||
product_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("fulfillment_base_products.id"), primary_key=True
|
||||
)
|
||||
|
||||
quantity: Mapped[int] = mapped_column(default=1)
|
||||
comment: Mapped[str] = mapped_column(comment="Комментарий к товару")
|
||||
|
||||
deal: Mapped["Deal"] = relationship(backref="deal_products")
|
||||
product: Mapped["Product"] = relationship()
|
||||
|
||||
product_services: Mapped[list["DealProductService"]] = relationship(
|
||||
back_populates="deal_product",
|
||||
primaryjoin="and_(DealProduct.deal_id==DealProductService.deal_id, DealProduct.product_id==DealProductService.product_id)",
|
||||
)
|
||||
|
||||
|
||||
class DealProductService(BaseModel, PriceMixin):
|
||||
__tablename__ = "fulfillment_base_deal_products_services"
|
||||
|
||||
deal_id: Mapped[int] = mapped_column(primary_key=True)
|
||||
product_id: Mapped[int] = mapped_column(primary_key=True)
|
||||
service_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("fulfillment_base_services.id"), primary_key=True
|
||||
)
|
||||
|
||||
is_fixed_price: Mapped[bool] = mapped_column(
|
||||
default=False, server_default="0", comment="Фиксированная цена"
|
||||
)
|
||||
|
||||
deal_product: Mapped["DealProduct"] = relationship(
|
||||
back_populates="product_services",
|
||||
primaryjoin="and_(DealProductService.deal_id==DealProduct.deal_id, DealProductService.product_id==DealProduct.product_id)",
|
||||
)
|
||||
service: Mapped["Service"] = relationship()
|
||||
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(
|
||||
["deal_id", "product_id"],
|
||||
[
|
||||
"fulfillment_base_deal_products.deal_id",
|
||||
"fulfillment_base_deal_products.product_id",
|
||||
],
|
||||
),
|
||||
)
|
||||
28
modules/fulfillment_base/models/deal_service.py
Normal file
28
modules/fulfillment_base/models/deal_service.py
Normal file
@ -0,0 +1,28 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models.base import BaseModel
|
||||
from models.mixins import PriceMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Deal
|
||||
from modules.fulfillment_base.models import Service
|
||||
|
||||
|
||||
class DealService(BaseModel, PriceMixin):
|
||||
__tablename__ = "fulfillment_base_deal_services"
|
||||
|
||||
deal_id: Mapped[int] = mapped_column(ForeignKey("deals.id"), primary_key=True)
|
||||
deal: Mapped["Deal"] = relationship(backref="deal_services")
|
||||
|
||||
service_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("fulfillment_base_services.id"), primary_key=True
|
||||
)
|
||||
service: Mapped["Service"] = relationship()
|
||||
|
||||
quantity: Mapped[int] = mapped_column(default=1)
|
||||
is_fixed_price: Mapped[bool] = mapped_column(
|
||||
default=False, server_default="0", comment="Фиксированная цена"
|
||||
)
|
||||
40
modules/fulfillment_base/models/product.py
Normal file
40
modules/fulfillment_base/models/product.py
Normal file
@ -0,0 +1,40 @@
|
||||
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
|
||||
|
||||
|
||||
class Product(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
__tablename__ = "fulfillment_base_products"
|
||||
|
||||
name: Mapped[str] = mapped_column()
|
||||
article: Mapped[str] = mapped_column(index=True)
|
||||
factory_article: Mapped[str] = mapped_column(
|
||||
index=True, default="", server_default=""
|
||||
)
|
||||
brand: Mapped[Optional[str]] = mapped_column(comment="Бренд")
|
||||
color: Mapped[Optional[str]] = mapped_column(comment="Цвет")
|
||||
composition: Mapped[Optional[str]] = mapped_column(comment="Состав")
|
||||
size: Mapped[Optional[str]] = mapped_column(comment="Размер")
|
||||
additional_info: Mapped[Optional[str]] = mapped_column(
|
||||
comment="Дополнительная информация"
|
||||
)
|
||||
|
||||
images: Mapped[list["ProductImage"]] = relationship(
|
||||
"ProductImage",
|
||||
back_populates="product",
|
||||
lazy="selectin",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class ProductImage(BaseModel, IdMixin):
|
||||
__tablename__ = "fulfillment_base_product_images"
|
||||
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey("fulfillment_base_products.id"))
|
||||
product: Mapped["Product"] = relationship(back_populates="images")
|
||||
|
||||
image_url: Mapped[str] = mapped_column(nullable=False)
|
||||
73
modules/fulfillment_base/models/service.py
Normal file
73
modules/fulfillment_base/models/service.py
Normal file
@ -0,0 +1,73 @@
|
||||
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, CostMixin, PriceMixin
|
||||
from modules.fulfillment_base import enums
|
||||
|
||||
services_kit_services = Table(
|
||||
"fulfillment_base_services_kit_services",
|
||||
BaseModel.metadata,
|
||||
Column("services_kit_id", ForeignKey("fulfillment_base_services_kits.id")),
|
||||
Column("service_id", ForeignKey("fulfillment_base_services.id")),
|
||||
)
|
||||
|
||||
|
||||
class Service(BaseModel, IdMixin, SoftDeleteMixin, PriceMixin, CostMixin):
|
||||
__tablename__ = "fulfillment_base_services"
|
||||
|
||||
name: Mapped[str] = mapped_column(index=True)
|
||||
|
||||
price_ranges: Mapped[list["ServicePriceRange"]] = relationship(
|
||||
back_populates="service",
|
||||
lazy="selectin",
|
||||
order_by="asc(ServicePriceRange.from_quantity)",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
category_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("fulfillment_base_service_categories.id"),
|
||||
comment="ID категории услуги",
|
||||
)
|
||||
category: Mapped["ServiceCategory"] = relationship("ServiceCategory", lazy="joined")
|
||||
|
||||
service_type: Mapped[int] = mapped_column(
|
||||
server_default=f"{enums.service.ServiceType.DEAL_SERVICE}",
|
||||
comment="Тип услуги",
|
||||
)
|
||||
lexorank: Mapped[str] = mapped_column(comment="Ранг услуги")
|
||||
|
||||
|
||||
class ServiceCategory(BaseModel, IdMixin):
|
||||
__tablename__ = "fulfillment_base_service_categories"
|
||||
|
||||
name: Mapped[str] = mapped_column()
|
||||
is_deleted: Mapped[bool] = mapped_column(
|
||||
default=False, comment="Удалена ли категория"
|
||||
)
|
||||
|
||||
deal_service_rank: Mapped[str] = mapped_column(comment="Ранг услуги для сделки")
|
||||
product_service_rank: Mapped[str] = mapped_column(comment="Ранг услуги для товара")
|
||||
|
||||
|
||||
class ServicesKit(BaseModel, IdMixin):
|
||||
__tablename__ = "fulfillment_base_services_kits"
|
||||
|
||||
name: Mapped[str] = mapped_column()
|
||||
service_type: Mapped[int] = mapped_column(
|
||||
server_default=f"{enums.ServiceType.DEAL_SERVICE}",
|
||||
comment="Тип услуги",
|
||||
)
|
||||
services: Mapped[list["Service"]] = relationship(
|
||||
secondary=services_kit_services, lazy="selectin"
|
||||
)
|
||||
|
||||
|
||||
class ServicePriceRange(BaseModel, IdMixin, PriceMixin):
|
||||
__tablename__ = "fulfillment_base_service_price_ranges"
|
||||
|
||||
service_id: Mapped[int] = mapped_column(ForeignKey("fulfillment_base_services.id"))
|
||||
service: Mapped[Service] = relationship(back_populates="price_ranges")
|
||||
|
||||
from_quantity: Mapped[int] = mapped_column(comment="От количества")
|
||||
to_quantity: Mapped[int] = mapped_column(comment="До количества")
|
||||
Reference in New Issue
Block a user