Fix few issues
This commit is contained in:
@@ -340,10 +340,143 @@ class InventoryServiceClient(BaseServiceClient):
|
||||
error=str(e), tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
# ================================================================
|
||||
# PRODUCT TRANSFORMATION
|
||||
# ================================================================
|
||||
|
||||
async def create_transformation(
|
||||
self,
|
||||
transformation_data: Dict[str, Any],
|
||||
tenant_id: str
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Create a product transformation (e.g., par-baked to fully baked)"""
|
||||
try:
|
||||
result = await self.post("transformations", data=transformation_data, tenant_id=tenant_id)
|
||||
if result:
|
||||
logger.info("Created product transformation",
|
||||
transformation_reference=result.get('transformation_reference'),
|
||||
source_stage=transformation_data.get('source_stage'),
|
||||
target_stage=transformation_data.get('target_stage'),
|
||||
tenant_id=tenant_id)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error("Error creating transformation",
|
||||
error=str(e), transformation_data=transformation_data, tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
async def create_par_bake_transformation(
|
||||
self,
|
||||
source_ingredient_id: Union[str, UUID],
|
||||
target_ingredient_id: Union[str, UUID],
|
||||
quantity: float,
|
||||
tenant_id: str,
|
||||
target_batch_number: Optional[str] = None,
|
||||
expiration_hours: int = 24,
|
||||
notes: Optional[str] = None
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Convenience method for par-baked to fresh transformation"""
|
||||
try:
|
||||
params = {
|
||||
"source_ingredient_id": str(source_ingredient_id),
|
||||
"target_ingredient_id": str(target_ingredient_id),
|
||||
"quantity": quantity,
|
||||
"expiration_hours": expiration_hours
|
||||
}
|
||||
|
||||
if target_batch_number:
|
||||
params["target_batch_number"] = target_batch_number
|
||||
if notes:
|
||||
params["notes"] = notes
|
||||
|
||||
result = await self.post("transformations/par-bake-to-fresh", params=params, tenant_id=tenant_id)
|
||||
if result:
|
||||
logger.info("Created par-bake transformation",
|
||||
transformation_id=result.get('transformation_id'),
|
||||
quantity=quantity, tenant_id=tenant_id)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error("Error creating par-bake transformation",
|
||||
error=str(e), source_ingredient_id=source_ingredient_id,
|
||||
target_ingredient_id=target_ingredient_id, tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
async def get_transformations(
|
||||
self,
|
||||
tenant_id: str,
|
||||
ingredient_id: Optional[Union[str, UUID]] = None,
|
||||
source_stage: Optional[str] = None,
|
||||
target_stage: Optional[str] = None,
|
||||
days_back: Optional[int] = None,
|
||||
skip: int = 0,
|
||||
limit: int = 100
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Get product transformations with filtering"""
|
||||
try:
|
||||
params = {
|
||||
"skip": skip,
|
||||
"limit": limit
|
||||
}
|
||||
|
||||
if ingredient_id:
|
||||
params["ingredient_id"] = str(ingredient_id)
|
||||
if source_stage:
|
||||
params["source_stage"] = source_stage
|
||||
if target_stage:
|
||||
params["target_stage"] = target_stage
|
||||
if days_back:
|
||||
params["days_back"] = days_back
|
||||
|
||||
result = await self.get("transformations", tenant_id=tenant_id, params=params)
|
||||
transformations = result if isinstance(result, list) else []
|
||||
|
||||
logger.info("Retrieved transformations from inventory service",
|
||||
count=len(transformations), tenant_id=tenant_id)
|
||||
return transformations
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error fetching transformations",
|
||||
error=str(e), tenant_id=tenant_id)
|
||||
return []
|
||||
|
||||
async def get_transformation_by_id(
|
||||
self,
|
||||
transformation_id: Union[str, UUID],
|
||||
tenant_id: str
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Get specific transformation by ID"""
|
||||
try:
|
||||
result = await self.get(f"transformations/{transformation_id}", tenant_id=tenant_id)
|
||||
if result:
|
||||
logger.info("Retrieved transformation by ID",
|
||||
transformation_id=transformation_id, tenant_id=tenant_id)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error("Error fetching transformation by ID",
|
||||
error=str(e), transformation_id=transformation_id, tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
async def get_transformation_summary(
|
||||
self,
|
||||
tenant_id: str,
|
||||
days_back: int = 30
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Get transformation summary for dashboard"""
|
||||
try:
|
||||
params = {"days_back": days_back}
|
||||
result = await self.get("transformations/summary", tenant_id=tenant_id, params=params)
|
||||
if result:
|
||||
logger.info("Retrieved transformation summary",
|
||||
days_back=days_back, tenant_id=tenant_id)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error("Error fetching transformation summary",
|
||||
error=str(e), tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
# ================================================================
|
||||
# UTILITY METHODS
|
||||
# ================================================================
|
||||
|
||||
|
||||
async def health_check(self) -> bool:
|
||||
"""Check if inventory service is healthy"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user