feat: deal product services
This commit is contained in:
@@ -21,11 +21,20 @@ class DealService(BaseModel):
|
||||
|
||||
class DealProductService(BaseModel):
|
||||
__tablename__ = 'deal_product_services'
|
||||
deal_id = Column(Integer, nullable=False, primary_key=True, comment='ID Сделки')
|
||||
product_id = Column(Integer, nullable=False, primary_key=True, comment='ID Продукта')
|
||||
service_id = Column(Integer, ForeignKey('services.id'), nullable=False, comment='ID Услуги')
|
||||
deal_id = Column(Integer, primary_key=True, nullable=False, comment='ID Сделки')
|
||||
product_id = Column(Integer, primary_key=True, nullable=False, comment='ID Продукта')
|
||||
service_id = Column(Integer, ForeignKey('services.id'), primary_key=True, nullable=False, comment='ID Услуги')
|
||||
price = Column(Integer, nullable=False, comment='Цена услуги')
|
||||
|
||||
deal_product = relationship('DealProduct',
|
||||
back_populates='services',
|
||||
primaryjoin="and_(DealProductService.deal_id == DealProduct.deal_id, "
|
||||
"DealProductService.product_id == DealProduct.product_id)",
|
||||
foreign_keys=[deal_id, product_id])
|
||||
service = relationship('Service',
|
||||
foreign_keys=[service_id],
|
||||
lazy='joined')
|
||||
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(
|
||||
['deal_id', 'product_id'],
|
||||
@@ -33,21 +42,28 @@ class DealProductService(BaseModel):
|
||||
),
|
||||
)
|
||||
|
||||
deal_product = relationship('DealProduct', back_populates='services')
|
||||
service = relationship('Service', lazy='joined')
|
||||
|
||||
|
||||
class DealProduct(BaseModel):
|
||||
__tablename__ = 'deal_products'
|
||||
deal_id = Column(Integer, ForeignKey('deals.id'), nullable=False, comment='ID Сделки', primary_key=True)
|
||||
product_id = Column(Integer, ForeignKey('products.id'), nullable=False, comment='ID Продукта', primary_key=True)
|
||||
deal_id = Column(Integer, ForeignKey('deals.id'), primary_key=True, nullable=False, comment='ID Сделки')
|
||||
product_id = Column(Integer, ForeignKey('products.id'), primary_key=True, nullable=False, comment='ID Продукта')
|
||||
quantity = Column(Integer, nullable=False, comment='Кол-во продукта')
|
||||
|
||||
deal = relationship('Deal', back_populates='products')
|
||||
product = relationship('Product')
|
||||
deal = relationship('Deal',
|
||||
back_populates='products',
|
||||
foreign_keys=[deal_id])
|
||||
product = relationship('Product',
|
||||
lazy='joined',
|
||||
foreign_keys=[product_id])
|
||||
|
||||
services = relationship('DealProductService', back_populates='deal_product', lazy='joined',
|
||||
cascade="all, delete-orphan")
|
||||
services = relationship('DealProductService',
|
||||
back_populates='deal_product',
|
||||
cascade="all, delete-orphan",
|
||||
primaryjoin="and_(DealProductService.deal_id == DealProduct.deal_id, "
|
||||
"DealProductService.product_id == DealProduct.product_id)",
|
||||
foreign_keys=[DealProductService.deal_id, DealProductService.product_id],
|
||||
lazy='joined'
|
||||
)
|
||||
|
||||
|
||||
barcode_template_attribute_link = Table(
|
||||
|
||||
Reference in New Issue
Block a user