feat: deal product services

This commit is contained in:
2024-05-13 07:46:13 +03:00
parent e9aec10feb
commit be650aca74
10 changed files with 136 additions and 10 deletions

View File

@@ -33,6 +33,8 @@ class Deal(BaseModel):
is_completed = Column(Boolean, nullable=False, server_default='0', default=False, comment='Завершена')
services = relationship('DealService', back_populates='deal', cascade="all, delete-orphan")
product_services = relationship('DealProductService', back_populates='deal', cascade="all, delete-orphan")
products = relationship('DealProduct', back_populates='deal', cascade="all, delete-orphan")
# TODO remake with sequence

View File

@@ -1,4 +1,4 @@
from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy import Table, Column, Integer, ForeignKey, Boolean
from sqlalchemy.orm import relationship
from models.base import metadata, BaseModel
@@ -16,6 +16,7 @@ class DealService(BaseModel):
service = relationship('Service')
quantity = Column(Integer, nullable=False, comment='Кол-во услуги')
price = Column(Integer, nullable=False, comment='Цена услуги')
class DealProduct(BaseModel):
@@ -33,6 +34,27 @@ class DealProduct(BaseModel):
quantity = Column(Integer, nullable=False, comment='Кол-во продукта')
class DealProductService(BaseModel):
__tablename__ = 'deal_product_services'
deal_id = Column(Integer,
ForeignKey('deals.id'),
nullable=False,
comment='ID Сделки',
primary_key=True)
deal = relationship('Deal', back_populates='product_services')
product_id = Column(Integer, ForeignKey('products.id'), nullable=False, comment='ID Продукта', primary_key=True)
product = relationship('Product')
service_id = Column(Integer, ForeignKey('services.id'), nullable=False, comment='ID Услуги', primary_key=True)
service = relationship('Service')
quantity = Column(Integer, nullable=False, comment='Кол-во продукта')
price = Column(Integer, nullable=False, comment='Цена услуги')
link_to_product_quantity = Column(Boolean, nullable=False, comment='Связь с количеством продукта')
barcode_template_attribute_link = Table(
'barcode_template_attribute_links',
BaseModel.metadata,

View File

@@ -1,6 +1,7 @@
from sqlalchemy import Column, Integer, String, ForeignKey, Double
from sqlalchemy import Column, Integer, String, ForeignKey, Double, asc
from sqlalchemy.orm import relationship, mapped_column, Mapped
import enums.service
from models import BaseModel
@@ -10,9 +11,26 @@ class Service(BaseModel):
name = Column(String, nullable=False, comment='Название услуги')
category_id = Column(Integer, ForeignKey('service_categories.id'), nullable=False, comment='ID категории услуги')
category = relationship('ServiceCategory')
category = relationship('ServiceCategory', lazy='joined')
price = Column(Double, nullable=False, comment='Стоимость услуги')
service_type = Column(Integer,
server_default=f'{enums.service.ServiceType.DEAL_SERVICE}',
nullable=False,
comment='Тип услуги')
price_ranges = relationship('ServicePriceRange', back_populates='service', lazy='selectin',
order_by="asc(ServicePriceRange.from_quantity)")
class ServicePriceRange(BaseModel):
__tablename__ = 'service_price_ranges'
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
service_id = Column(Integer, ForeignKey('services.id'), nullable=False, comment='ID услуги')
service = relationship('Service', back_populates='price_ranges')
from_quantity = Column(Integer, nullable=False, comment='От количества')
to_quantity = Column(Integer, nullable=False, comment='До количества')
price = Column(Double, nullable=False, comment='Цена')
class ServiceCategory(BaseModel):