feat: attrs on product
This commit is contained in:
@@ -2,7 +2,9 @@ from .article_attribute_getter import ArticleAttributeGetter
|
|||||||
from .brand_attribute_getter import BrandAttributeGetter
|
from .brand_attribute_getter import BrandAttributeGetter
|
||||||
from .client_name_attribute_getter import ClientNameAttributeGetter
|
from .client_name_attribute_getter import ClientNameAttributeGetter
|
||||||
from .color_attribute_getter import ColorAttributeGetter
|
from .color_attribute_getter import ColorAttributeGetter
|
||||||
|
from .company_name_attribute_getter import CompanyNameAttributeGetter
|
||||||
from .composition_attribute_getter import CompositionAttributeGetter
|
from .composition_attribute_getter import CompositionAttributeGetter
|
||||||
|
from .inn_attribute_getter import InnAttributeGetter
|
||||||
from .name_attribute_getter import NameAttributeGetter
|
from .name_attribute_getter import NameAttributeGetter
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +18,10 @@ class AttributeWriterFactory:
|
|||||||
return ArticleAttributeGetter()
|
return ArticleAttributeGetter()
|
||||||
case 'client.name':
|
case 'client.name':
|
||||||
return ClientNameAttributeGetter()
|
return ClientNameAttributeGetter()
|
||||||
|
case 'client.company_name':
|
||||||
|
return CompanyNameAttributeGetter()
|
||||||
|
case 'client.inn':
|
||||||
|
return InnAttributeGetter()
|
||||||
case 'brand':
|
case 'brand':
|
||||||
return BrandAttributeGetter()
|
return BrandAttributeGetter()
|
||||||
case 'color':
|
case 'color':
|
||||||
|
|||||||
11
barcodes/attributes/company_name_attribute_getter.py
Normal file
11
barcodes/attributes/company_name_attribute_getter.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from barcodes.attributes.base import BaseAttributeGetter
|
||||||
|
from models import Product, Client
|
||||||
|
|
||||||
|
|
||||||
|
class CompanyNameAttributeGetter(BaseAttributeGetter):
|
||||||
|
def get_value(self, product: Product):
|
||||||
|
client: Client = product.client
|
||||||
|
result = client.company_name
|
||||||
|
if not result:
|
||||||
|
result = ''
|
||||||
|
return result
|
||||||
12
barcodes/attributes/inn_attribute_getter.py
Normal file
12
barcodes/attributes/inn_attribute_getter.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from barcodes.attributes.base import BaseAttributeGetter
|
||||||
|
from models import Product, Client, ClientDetails
|
||||||
|
|
||||||
|
|
||||||
|
class InnAttributeGetter(BaseAttributeGetter):
|
||||||
|
def get_value(self, product: Product):
|
||||||
|
client: Client = product.client
|
||||||
|
client_details: ClientDetails = client.details
|
||||||
|
result = client_details.inn
|
||||||
|
if not result:
|
||||||
|
result = ''
|
||||||
|
return result
|
||||||
@@ -8,10 +8,18 @@ class Client(BaseModel):
|
|||||||
__tablename__ = 'clients'
|
__tablename__ = 'clients'
|
||||||
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
||||||
name = Column(String, nullable=False, unique=True, comment='Название клиента')
|
name = Column(String, nullable=False, unique=True, comment='Название клиента')
|
||||||
|
|
||||||
|
# TODO replace with additional model
|
||||||
|
company_name = Column(String,
|
||||||
|
nullable=False,
|
||||||
|
server_default='',
|
||||||
|
comment='Название компании')
|
||||||
|
|
||||||
created_at = Column(DateTime, nullable=False, comment='Дата создания')
|
created_at = Column(DateTime, nullable=False, comment='Дата создания')
|
||||||
|
|
||||||
products = relationship('Product', back_populates='client')
|
products = relationship('Product', back_populates='client')
|
||||||
details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete')
|
details = relationship('ClientDetails', uselist=False, back_populates='client', cascade='all, delete',
|
||||||
|
lazy='joined')
|
||||||
|
|
||||||
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
|
barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
|
||||||
barcode_template = relationship('BarcodeTemplate', lazy='selectin')
|
barcode_template = relationship('BarcodeTemplate', lazy='selectin')
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class ClientDetailsSchema(CustomModelCamel):
|
|||||||
class ClientSchema(CustomModelCamel):
|
class ClientSchema(CustomModelCamel):
|
||||||
id: int
|
id: int
|
||||||
name: str
|
name: str
|
||||||
|
company_name: str
|
||||||
barcode_template: BarcodeTemplateSchema | None = None
|
barcode_template: BarcodeTemplateSchema | None = None
|
||||||
details: ClientDetailsSchema | None = None
|
details: ClientDetailsSchema | None = None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user