feat: attrs on product
This commit is contained in:
		@@ -1,5 +1,8 @@
 | 
			
		||||
from .article_attribute_getter import ArticleAttributeGetter
 | 
			
		||||
from .brand_attribute_getter import BrandAttributeGetter
 | 
			
		||||
from .client_name_attribute_getter import ClientNameAttributeGetter
 | 
			
		||||
from .color_attribute_getter import ColorAttributeGetter
 | 
			
		||||
from .composition_attribute_getter import CompositionAttributeGetter
 | 
			
		||||
from .name_attribute_getter import NameAttributeGetter
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -13,5 +16,11 @@ class AttributeWriterFactory:
 | 
			
		||||
                return ArticleAttributeGetter()
 | 
			
		||||
            case 'client.name':
 | 
			
		||||
                return ClientNameAttributeGetter()
 | 
			
		||||
            case 'brand':
 | 
			
		||||
                return BrandAttributeGetter()
 | 
			
		||||
            case 'color':
 | 
			
		||||
                return ColorAttributeGetter()
 | 
			
		||||
            case 'composition':
 | 
			
		||||
                return CompositionAttributeGetter()
 | 
			
		||||
            case _:
 | 
			
		||||
                return None
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								barcodes/attributes/brand_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								barcodes/attributes/brand_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
from barcodes.attributes.base import BaseAttributeGetter
 | 
			
		||||
from models import Product
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BrandAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        result = product.brand
 | 
			
		||||
        if not result:
 | 
			
		||||
            result = ''
 | 
			
		||||
        return result
 | 
			
		||||
							
								
								
									
										11
									
								
								barcodes/attributes/color_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								barcodes/attributes/color_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
from barcodes.attributes.base import BaseAttributeGetter
 | 
			
		||||
from models import Product
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ColorAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        result = product.color
 | 
			
		||||
        if not result:
 | 
			
		||||
            result = ''
 | 
			
		||||
        return result
 | 
			
		||||
							
								
								
									
										11
									
								
								barcodes/attributes/composition_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								barcodes/attributes/composition_attribute_getter.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
from barcodes.attributes.base import BaseAttributeGetter
 | 
			
		||||
from models import Product
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CompositionAttributeGetter(BaseAttributeGetter):
 | 
			
		||||
 | 
			
		||||
    def get_value(self, product: Product):
 | 
			
		||||
        result = product.composition
 | 
			
		||||
        if not result:
 | 
			
		||||
            result = ''
 | 
			
		||||
        return result
 | 
			
		||||
@@ -17,6 +17,12 @@ class Product(BaseModel):
 | 
			
		||||
    barcode_template_id = Column(Integer, ForeignKey('barcode_templates.id'), nullable=True)
 | 
			
		||||
    barcode_template = relationship('BarcodeTemplate', lazy='joined')
 | 
			
		||||
 | 
			
		||||
    # Attributes
 | 
			
		||||
    # TODO move to another table
 | 
			
		||||
    brand = Column(String, nullable=True, comment='Бренд')
 | 
			
		||||
    color = Column(String, nullable=True, comment='Цвет')
 | 
			
		||||
    composition = Column(String, nullable=True, comment='Состав')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ProductBarcode(BaseModel):
 | 
			
		||||
    __tablename__ = 'product_barcodes'
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,11 @@ class ProductSchema(CustomModelCamel):
 | 
			
		||||
    barcodes: list[str]
 | 
			
		||||
    barcode_template: BarcodeTemplateSchema | None = None
 | 
			
		||||
 | 
			
		||||
    # Attributes
 | 
			
		||||
    brand: str | None = None
 | 
			
		||||
    color: str | None = None
 | 
			
		||||
    composition: str | None = None
 | 
			
		||||
 | 
			
		||||
    @field_validator('barcodes', mode="before")
 | 
			
		||||
    def barcodes_to_list(cls, v):
 | 
			
		||||
        if isinstance(v, list) and all([type(barcode) is ProductBarcode for barcode in v]):
 | 
			
		||||
@@ -32,6 +37,7 @@ class ProductCreateRequest(CustomModelCamel):
 | 
			
		||||
    barcodes: List[str]
 | 
			
		||||
    barcode_template: BarcodeTemplateSchema | None = None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ProductDeleteRequest(CustomModelCamel):
 | 
			
		||||
    product_id: int
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user