feat: temp barcode templates

This commit is contained in:
2024-05-03 17:07:36 +03:00
parent 4f62bb2468
commit 99f0308a8a
10 changed files with 341 additions and 1 deletions

View File

@@ -6,4 +6,5 @@ from .client import *
from .service import *
from .product import *
from .secondary import *
from .barcode import *
configure_mappers()

22
models/barcode.py Normal file
View File

@@ -0,0 +1,22 @@
from sqlalchemy import Integer, Column, String, Boolean
from sqlalchemy.orm import relationship
from models import BaseModel
class BarcodeTemplateAttribute(BaseModel):
__tablename__ = 'barcode_template_attributes'
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
name = Column(String, nullable=False, index=True, comment='Название атрибута')
label = Column(String, nullable=False, index=True, comment='Метка атрибута')
class BarcodeTemplate(BaseModel):
__tablename__ = 'barcode_templates'
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
name = Column(String, nullable=False, index=True, comment='Название шаблона')
attributes = relationship('BarcodeTemplateAttributeLink',
back_populates='barcode_template',
cascade="all, delete-orphan",
lazy='joined')
is_default = Column(Boolean, nullable=False, default=False, comment='По умолчанию')

View File

@@ -11,9 +11,11 @@ class Client(BaseModel):
created_at = Column(DateTime, nullable=False, comment='Дата создания')
products = relationship('Product', back_populates='client')
details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete')
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
barcode_template = relationship('BarcodeTemplate')
class ClientDetails(BaseModel):
__tablename__ = 'client_details'

View File

@@ -18,6 +18,9 @@ class Product(BaseModel):
client = relationship('Client', back_populates='products')
barcodes = relationship('ProductBarcode', back_populates='product', cascade="all, delete-orphan")
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
barcode_template = relationship('BarcodeTemplate')
class ProductBarcode(BaseModel):
__tablename__ = 'product_barcodes'

View File

@@ -31,3 +31,20 @@ class DealProduct(BaseModel):
product = relationship('Product')
quantity = Column(Integer, nullable=False, comment='Кол-во продукта')
class BarcodeTemplateAttributeLink(BaseModel):
__tablename__ = 'barcode_template_attributes_links'
barcode_template_id = Column(Integer,
ForeignKey('barcode_templates.id'),
nullable=False,
comment='ID Шаблона ШК',
primary_key=True)
barcode_template = relationship('BarcodeTemplate', back_populates='attributes')
attribute_id = Column(Integer,
ForeignKey('barcode_template_attributes.id'),
nullable=False,
comment='ID Атрибута',
primary_key=True)
attribute = relationship('BarcodeTemplateAttribute')