feat: article now is not required
This commit is contained in:
		@@ -8,7 +8,7 @@ class Product(BaseModel):
 | 
				
			|||||||
    __tablename__ = 'products'
 | 
					    __tablename__ = 'products'
 | 
				
			||||||
    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, index=True)
 | 
					    name = Column(String, nullable=False, index=True)
 | 
				
			||||||
    article = Column(String, nullable=False, index=True)
 | 
					    article = Column(String, nullable=False, default='', server_default='', index=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    client_id = Column(Integer, ForeignKey('clients.id'), nullable=False, comment='ID сделки')
 | 
					    client_id = Column(Integer, ForeignKey('clients.id'), nullable=False, comment='ID сделки')
 | 
				
			||||||
    client = relationship('Client', back_populates='products')
 | 
					    client = relationship('Client', back_populates='products')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ from models import ProductBarcode
 | 
				
			|||||||
# region Entities
 | 
					# region Entities
 | 
				
			||||||
class BaseProductSchema(CustomModelCamel):
 | 
					class BaseProductSchema(CustomModelCamel):
 | 
				
			||||||
    name: str
 | 
					    name: str
 | 
				
			||||||
    article: str
 | 
					    article: str | None = ''
 | 
				
			||||||
    client_id: int
 | 
					    client_id: int
 | 
				
			||||||
    barcodes: list[str]
 | 
					    barcodes: list[str]
 | 
				
			||||||
    barcode_template: BarcodeTemplateSchema | None = None
 | 
					    barcode_template: BarcodeTemplateSchema | None = None
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,14 +14,14 @@ class ProductService(BaseService):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async def create(self, request: ProductCreateRequest) -> ProductCreateResponse:
 | 
					    async def create(self, request: ProductCreateRequest) -> ProductCreateResponse:
 | 
				
			||||||
        # Unique article validation
 | 
					        # Unique article validation
 | 
				
			||||||
        existing_product_query = await self.session.execute(
 | 
					        # existing_product_query = await self.session.execute(
 | 
				
			||||||
            select(Product)
 | 
					        #     select(Product)
 | 
				
			||||||
            .where(Product.client_id == request.client_id,
 | 
					        #     .where(Product.client_id == request.client_id,
 | 
				
			||||||
                   Product.article == request.article)
 | 
					        #            Product.article == request.article)
 | 
				
			||||||
        )
 | 
					        # )
 | 
				
			||||||
        existing_product = existing_product_query.first()
 | 
					        # existing_product = existing_product_query.first()
 | 
				
			||||||
        if existing_product:
 | 
					        # if existing_product:
 | 
				
			||||||
            return ProductCreateResponse(ok=False, message='Товар с таким артикулом уже существует у клиента')
 | 
					        #     return ProductCreateResponse(ok=False, message='Товар с таким артикулом уже существует у клиента')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Creating product
 | 
					        # Creating product
 | 
				
			||||||
        product_dict = request.dict()
 | 
					        product_dict = request.dict()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user