Add procurement management logic
This commit is contained in:
@@ -301,80 +301,3 @@ async def validate_sales_record(
|
||||
except Exception as e:
|
||||
logger.error("Failed to validate sales record", error=str(e), record_id=record_id, tenant_id=tenant_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to validate sales record: {str(e)}")
|
||||
|
||||
|
||||
# ================================================================
|
||||
# INVENTORY INTEGRATION ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
@router.get("/tenants/{tenant_id}/inventory/products/search")
|
||||
async def search_inventory_products(
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
search: str = Query(..., description="Search term"),
|
||||
product_type: Optional[str] = Query(None, description="Product type filter"),
|
||||
current_tenant: str = Depends(get_current_tenant_id_dep),
|
||||
sales_service: SalesService = Depends(get_sales_service)
|
||||
):
|
||||
"""Search products in inventory service"""
|
||||
try:
|
||||
# Verify tenant access
|
||||
if str(tenant_id) != current_tenant:
|
||||
raise HTTPException(status_code=403, detail="Access denied to this tenant")
|
||||
|
||||
products = await sales_service.search_inventory_products(search, tenant_id, product_type)
|
||||
|
||||
return {"items": products, "count": len(products)}
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to search inventory products", error=str(e), tenant_id=tenant_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to search inventory products: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/inventory/products/{product_id}")
|
||||
async def get_inventory_product(
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
product_id: UUID = Path(..., description="Product ID from inventory service"),
|
||||
current_tenant: str = Depends(get_current_tenant_id_dep),
|
||||
sales_service: SalesService = Depends(get_sales_service)
|
||||
):
|
||||
"""Get product details from inventory service"""
|
||||
try:
|
||||
# Verify tenant access
|
||||
if str(tenant_id) != current_tenant:
|
||||
raise HTTPException(status_code=403, detail="Access denied to this tenant")
|
||||
|
||||
product = await sales_service.get_inventory_product(product_id, tenant_id)
|
||||
|
||||
if not product:
|
||||
raise HTTPException(status_code=404, detail="Product not found in inventory")
|
||||
|
||||
return product
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error("Failed to get inventory product", error=str(e), product_id=product_id, tenant_id=tenant_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to get inventory product: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/inventory/products/category/{category}")
|
||||
async def get_inventory_products_by_category(
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
category: str = Path(..., description="Product category"),
|
||||
product_type: Optional[str] = Query(None, description="Product type filter"),
|
||||
current_tenant: str = Depends(get_current_tenant_id_dep),
|
||||
sales_service: SalesService = Depends(get_sales_service)
|
||||
):
|
||||
"""Get products by category from inventory service"""
|
||||
try:
|
||||
# Verify tenant access
|
||||
if str(tenant_id) != current_tenant:
|
||||
raise HTTPException(status_code=403, detail="Access denied to this tenant")
|
||||
|
||||
products = await sales_service.get_inventory_products_by_category(category, tenant_id, product_type)
|
||||
|
||||
return {"items": products, "count": len(products)}
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to get inventory products by category", error=str(e), category=category, tenant_id=tenant_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to get inventory products by category: {str(e)}")
|
||||
Reference in New Issue
Block a user