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