feat: attrs on product
This commit is contained in:
		@@ -6,6 +6,7 @@ from .company_name_attribute_getter import CompanyNameAttributeGetter
 | 
			
		||||
from .composition_attribute_getter import CompositionAttributeGetter
 | 
			
		||||
from .inn_attribute_getter import InnAttributeGetter
 | 
			
		||||
from .name_attribute_getter import NameAttributeGetter
 | 
			
		||||
from .size_attribute_getter import SizeAttributeGetter
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AttributeWriterFactory:
 | 
			
		||||
@@ -28,5 +29,7 @@ class AttributeWriterFactory:
 | 
			
		||||
                return ColorAttributeGetter()
 | 
			
		||||
            case 'composition':
 | 
			
		||||
                return CompositionAttributeGetter()
 | 
			
		||||
            case 'size':
 | 
			
		||||
                return SizeAttributeGetter()
 | 
			
		||||
            case _:
 | 
			
		||||
                return None
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,5 @@ from models import Product
 | 
			
		||||
class BrandAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        result = product.brand
 | 
			
		||||
        if not result:
 | 
			
		||||
            result = ''
 | 
			
		||||
        return result
 | 
			
		||||
        return product.brand
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,4 @@ from models import Product
 | 
			
		||||
class ColorAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        result = product.color
 | 
			
		||||
        if not result:
 | 
			
		||||
            result = ''
 | 
			
		||||
        return result
 | 
			
		||||
        return product.color
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,4 @@ 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
 | 
			
		||||
        return client.company_name
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,4 @@ from models import Product
 | 
			
		||||
class CompositionAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        result = product.composition
 | 
			
		||||
        if not result:
 | 
			
		||||
            result = ''
 | 
			
		||||
        return result
 | 
			
		||||
        return product.composition
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,4 @@ 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
 | 
			
		||||
        return client_details.inn
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								barcodes/attributes/size_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								barcodes/attributes/size_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
from barcodes.attributes.base import BaseAttributeGetter
 | 
			
		||||
from models import Product
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SizeAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        return product.size
 | 
			
		||||
@@ -43,8 +43,8 @@ class BarcodeTemplate(BaseModel):
 | 
			
		||||
                                         lazy='selectin',
 | 
			
		||||
                                         back_populates='barcode_template',
 | 
			
		||||
                                         cascade="all, delete")
 | 
			
		||||
    additional_field = Column(String, nullable=True, comment='Дополнительное поле')
 | 
			
		||||
 | 
			
		||||
    is_default = Column(Boolean, nullable=False, default=False, comment='По умолчанию')
 | 
			
		||||
 | 
			
		||||
    size_id = Column(Integer, ForeignKey('barcode_template_sizes.id'), nullable=False)
 | 
			
		||||
    size = relationship('BarcodeTemplateSize', lazy='joined')
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ class Product(BaseModel):
 | 
			
		||||
    brand = Column(String, nullable=True, comment='Бренд')
 | 
			
		||||
    color = Column(String, nullable=True, comment='Цвет')
 | 
			
		||||
    composition = Column(String, nullable=True, comment='Состав')
 | 
			
		||||
    size = Column(String, nullable=True, comment='Размер')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ProductBarcode(BaseModel):
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ class BaseBarcodeTemplateSchema(CustomModelCamel):
 | 
			
		||||
    is_default: bool
 | 
			
		||||
    size: BarcodeTemplateSizeSchema
 | 
			
		||||
    additional_attributes: list[BarcodeTemplateAdditionalAttributeSchema]
 | 
			
		||||
    additional_field: str | None = None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BarcodeTemplateSchema(BaseBarcodeTemplateSchema):
 | 
			
		||||
@@ -43,6 +44,7 @@ class BarcodeAttributeSchema(CustomModelCamel):
 | 
			
		||||
class BarcodeSchema(CustomModelCamel):
 | 
			
		||||
    barcode: str
 | 
			
		||||
    attributes: List[BarcodeAttributeSchema]
 | 
			
		||||
    additional_field: str | None = None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# endregion
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ class ProductSchema(CustomModelCamel):
 | 
			
		||||
    brand: str | None = None
 | 
			
		||||
    color: str | None = None
 | 
			
		||||
    composition: str | None = None
 | 
			
		||||
    size: str | None = None
 | 
			
		||||
 | 
			
		||||
    @field_validator('barcodes', mode="before")
 | 
			
		||||
    def barcodes_to_list(cls, v):
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,8 @@ class BarcodeService(BaseService):
 | 
			
		||||
            if not attribute_getter:
 | 
			
		||||
                continue
 | 
			
		||||
            value = attribute_getter.get_value(product)
 | 
			
		||||
            if not value:
 | 
			
		||||
                continue
 | 
			
		||||
            attributes_list.append(
 | 
			
		||||
                BarcodeAttributeSchema(
 | 
			
		||||
                    name=attribute.name,
 | 
			
		||||
@@ -66,7 +68,8 @@ class BarcodeService(BaseService):
 | 
			
		||||
            )
 | 
			
		||||
        barcode = BarcodeSchema(
 | 
			
		||||
            barcode=request.barcode,
 | 
			
		||||
            attributes=attributes_list
 | 
			
		||||
            attributes=attributes_list,
 | 
			
		||||
            additional_field=barcode_template.additional_field
 | 
			
		||||
        )
 | 
			
		||||
        return GetProductBarcodeResponse(barcode=barcode)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user