feat: deal product services
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from sqlalchemy import Table, Column, Integer, ForeignKey, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy import Table, Column, Integer, ForeignKey, Boolean, and_, ForeignKeyConstraint
|
||||
from sqlalchemy.orm import relationship, foreign, remote
|
||||
|
||||
from models.base import metadata, BaseModel
|
||||
|
||||
@@ -19,40 +19,35 @@ class DealService(BaseModel):
|
||||
price = Column(Integer, nullable=False, comment='Цена услуги')
|
||||
|
||||
|
||||
class DealProduct(BaseModel):
|
||||
__tablename__ = 'deal_products'
|
||||
deal_id = Column(Integer,
|
||||
ForeignKey('deals.id'),
|
||||
nullable=False,
|
||||
comment='ID Сделки',
|
||||
primary_key=True)
|
||||
deal = relationship('Deal', back_populates='products')
|
||||
|
||||
product_id = Column(Integer, ForeignKey('products.id'), nullable=False, comment='ID Продукта', primary_key=True)
|
||||
product = relationship('Product')
|
||||
|
||||
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='Кол-во продукта')
|
||||
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 Услуги')
|
||||
price = Column(Integer, nullable=False, comment='Цена услуги')
|
||||
|
||||
link_to_product_quantity = Column(Boolean, nullable=False, comment='Связь с количеством продукта')
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(
|
||||
['deal_id', 'product_id'],
|
||||
['deal_products.deal_id', 'deal_products.product_id']
|
||||
),
|
||||
)
|
||||
|
||||
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)
|
||||
quantity = Column(Integer, nullable=False, comment='Кол-во продукта')
|
||||
|
||||
deal = relationship('Deal', back_populates='products')
|
||||
product = relationship('Product')
|
||||
|
||||
services = relationship('DealProductService', back_populates='deal_product', lazy='joined',
|
||||
cascade="all, delete-orphan")
|
||||
|
||||
|
||||
barcode_template_attribute_link = Table(
|
||||
|
||||
Reference in New Issue
Block a user