Files
bakery-ia/shared/clients/procurement_client.py

678 lines
22 KiB
Python
Raw Normal View History

2025-10-30 21:08:07 +01:00
"""
2025-11-30 09:12:40 +01:00
Procurement Service Client for Inter-Service Communication
Provides API client for procurement operations and internal transfers
2025-10-30 21:08:07 +01:00
"""
import structlog
2025-11-30 09:12:40 +01:00
from typing import Dict, Any, List, Optional
2025-10-30 21:08:07 +01:00
from datetime import date
from shared.clients.base_service_client import BaseServiceClient
from shared.config.base import BaseServiceSettings
logger = structlog.get_logger()
class ProcurementServiceClient(BaseServiceClient):
2025-11-30 09:12:40 +01:00
"""Client for communicating with the Procurement Service"""
2025-10-30 21:08:07 +01:00
2025-11-30 09:12:40 +01:00
def __init__(self, config: BaseServiceSettings, service_name: str = "unknown"):
super().__init__(service_name, config)
self.service_base_url = config.PROCUREMENT_SERVICE_URL
2025-10-30 21:08:07 +01:00
def get_service_base_path(self) -> str:
return "/api/v1"
# ================================================================
2025-11-30 09:12:40 +01:00
# PURCHASE ORDER ENDPOINTS
2025-10-30 21:08:07 +01:00
# ================================================================
2025-11-30 09:12:40 +01:00
async def create_purchase_order(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
order_data: Dict[str, Any]
2025-10-30 21:08:07 +01:00
) -> Optional[Dict[str, Any]]:
"""
2025-11-30 09:12:40 +01:00
Create a new purchase order
2025-10-30 21:08:07 +01:00
Args:
tenant_id: Tenant ID
2025-11-30 09:12:40 +01:00
order_data: Purchase order data
Returns:
Created purchase order
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.post(
"procurement/purchase-orders",
data=order_data,
tenant_id=tenant_id
)
if response:
logger.info("Created purchase order",
tenant_id=tenant_id,
po_number=response.get("po_number"))
2025-10-30 21:08:07 +01:00
return response
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error creating purchase order",
tenant_id=tenant_id,
error=str(e))
2025-10-30 21:08:07 +01:00
return None
2025-11-30 09:12:40 +01:00
async def get_purchase_order(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
po_id: str
2025-10-30 21:08:07 +01:00
) -> Optional[Dict[str, Any]]:
"""
2025-11-30 09:12:40 +01:00
Get a specific purchase order
2025-10-30 21:08:07 +01:00
Args:
tenant_id: Tenant ID
2025-11-30 09:12:40 +01:00
po_id: Purchase order ID
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
Purchase order details
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.get(
f"procurement/purchase-orders/{po_id}",
tenant_id=tenant_id
)
if response:
logger.info("Retrieved purchase order",
tenant_id=tenant_id,
po_id=po_id)
2025-10-30 21:08:07 +01:00
return response
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting purchase order",
tenant_id=tenant_id,
po_id=po_id,
error=str(e))
2025-10-30 21:08:07 +01:00
return None
2025-11-30 09:12:40 +01:00
async def update_purchase_order_status(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
po_id: str,
new_status: str,
user_id: str
2025-10-30 21:08:07 +01:00
) -> Optional[Dict[str, Any]]:
"""
2025-11-30 09:12:40 +01:00
Update purchase order status
2025-10-30 21:08:07 +01:00
Args:
tenant_id: Tenant ID
2025-11-30 09:12:40 +01:00
po_id: Purchase order ID
new_status: New status
user_id: User ID performing update
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
Updated purchase order
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.put(
f"procurement/purchase-orders/{po_id}/status",
data={
"status": new_status,
"updated_by_user_id": user_id
},
tenant_id=tenant_id
)
if response:
logger.info("Updated purchase order status",
tenant_id=tenant_id,
po_id=po_id,
new_status=new_status)
2025-10-30 21:08:07 +01:00
return response
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error updating purchase order status",
tenant_id=tenant_id,
po_id=po_id,
new_status=new_status,
error=str(e))
2025-10-30 21:08:07 +01:00
return None
2025-11-30 09:12:40 +01:00
async def get_pending_purchase_orders(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-12-05 20:07:01 +01:00
limit: int = 50,
enrich_supplier: bool = True
2025-10-30 21:08:07 +01:00
) -> Optional[List[Dict[str, Any]]]:
"""
2025-11-30 09:12:40 +01:00
Get pending purchase orders
2025-10-30 21:08:07 +01:00
Args:
tenant_id: Tenant ID
2025-11-30 09:12:40 +01:00
limit: Maximum number of results
2025-12-05 20:07:01 +01:00
enrich_supplier: Whether to include supplier details (default: True)
Set to False for faster queries when supplier data will be fetched separately
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
List of pending purchase orders
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.get(
"procurement/purchase-orders",
2025-12-05 20:07:01 +01:00
params={
"status": "pending_approval",
"limit": limit,
"enrich_supplier": enrich_supplier
},
2025-11-30 09:12:40 +01:00
tenant_id=tenant_id
)
2025-12-05 20:07:01 +01:00
2025-11-30 09:12:40 +01:00
if response:
logger.info("Retrieved pending purchase orders",
tenant_id=tenant_id,
2025-12-05 20:07:01 +01:00
count=len(response),
enriched=enrich_supplier)
2025-11-30 09:12:40 +01:00
return response if response else []
2025-10-30 21:08:07 +01:00
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting pending purchase orders",
tenant_id=tenant_id,
error=str(e))
return []
2025-10-30 21:08:07 +01:00
2025-12-05 20:07:01 +01:00
async def get_purchase_orders_by_supplier(
self,
tenant_id: str,
supplier_id: str,
date_from: Optional[date] = None,
date_to: Optional[date] = None,
status: Optional[str] = None,
limit: int = 100
) -> Optional[List[Dict[str, Any]]]:
"""
Get purchase orders for a specific supplier
Args:
tenant_id: Tenant ID
supplier_id: Supplier ID to filter by
date_from: Start date for filtering
date_to: End date for filtering
status: Status filter (e.g., 'approved', 'delivered')
limit: Maximum number of results
Returns:
List of purchase orders with items
"""
try:
params = {
"supplier_id": supplier_id,
"limit": limit
}
if date_from:
params["date_from"] = date_from.isoformat()
if date_to:
params["date_to"] = date_to.isoformat()
if status:
params["status"] = status
response = await self.get(
"procurement/purchase-orders",
params=params,
tenant_id=tenant_id
)
if response:
logger.info("Retrieved purchase orders by supplier",
tenant_id=tenant_id,
supplier_id=supplier_id,
count=len(response))
return response if response else []
except Exception as e:
logger.error("Error getting purchase orders by supplier",
tenant_id=tenant_id,
supplier_id=supplier_id,
error=str(e))
return []
2025-10-30 21:08:07 +01:00
# ================================================================
2025-11-30 09:12:40 +01:00
# INTERNAL TRANSFER ENDPOINTS (NEW FOR ENTERPRISE TIER)
2025-10-30 21:08:07 +01:00
# ================================================================
2025-11-30 09:12:40 +01:00
async def create_internal_purchase_order(
2025-10-30 21:08:07 +01:00
self,
2025-11-30 09:12:40 +01:00
parent_tenant_id: str,
child_tenant_id: str,
items: List[Dict[str, Any]],
delivery_date: date,
notes: Optional[str] = None
2025-10-30 21:08:07 +01:00
) -> Optional[Dict[str, Any]]:
"""
2025-11-30 09:12:40 +01:00
Create an internal purchase order from parent to child tenant
2025-10-30 21:08:07 +01:00
Args:
2025-11-30 09:12:40 +01:00
parent_tenant_id: Parent tenant ID (supplier)
child_tenant_id: Child tenant ID (buyer)
items: List of items with product_id, quantity, unit_of_measure
delivery_date: When child needs delivery
notes: Optional notes for the transfer
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
Created internal purchase order
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.post(
"procurement/internal-transfers",
data={
"destination_tenant_id": child_tenant_id,
"items": items,
"delivery_date": delivery_date.isoformat(),
"notes": notes
},
tenant_id=parent_tenant_id
)
if response:
logger.info("Created internal purchase order",
parent_tenant_id=parent_tenant_id,
child_tenant_id=child_tenant_id,
po_number=response.get("po_number"))
2025-10-30 21:08:07 +01:00
return response
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error creating internal purchase order",
parent_tenant_id=parent_tenant_id,
child_tenant_id=child_tenant_id,
error=str(e))
2025-10-30 21:08:07 +01:00
return None
2025-11-30 09:12:40 +01:00
async def get_approved_internal_purchase_orders(
2025-10-30 21:08:07 +01:00
self,
2025-11-30 09:12:40 +01:00
parent_tenant_id: str,
target_date: Optional[date] = None,
status: Optional[str] = "approved"
2025-10-30 21:08:07 +01:00
) -> Optional[List[Dict[str, Any]]]:
"""
2025-11-30 09:12:40 +01:00
Get approved internal purchase orders for parent tenant
2025-10-30 21:08:07 +01:00
Args:
2025-11-30 09:12:40 +01:00
parent_tenant_id: Parent tenant ID
target_date: Optional target date to filter
status: Status filter (default: approved)
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
List of approved internal purchase orders
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
params = {"status": status}
if target_date:
params["target_date"] = target_date.isoformat()
response = await self.get(
"procurement/internal-transfers",
params=params,
tenant_id=parent_tenant_id
)
if response:
logger.info("Retrieved internal purchase orders",
parent_tenant_id=parent_tenant_id,
count=len(response))
return response if response else []
2025-10-30 21:08:07 +01:00
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting internal purchase orders",
parent_tenant_id=parent_tenant_id,
error=str(e))
return []
2025-10-30 21:08:07 +01:00
2025-11-30 09:12:40 +01:00
async def approve_internal_purchase_order(
2025-10-30 21:08:07 +01:00
self,
2025-11-30 09:12:40 +01:00
parent_tenant_id: str,
po_id: str,
approved_by_user_id: str
2025-10-30 21:08:07 +01:00
) -> Optional[Dict[str, Any]]:
"""
2025-11-30 09:12:40 +01:00
Approve an internal purchase order
2025-10-30 21:08:07 +01:00
Args:
2025-11-30 09:12:40 +01:00
parent_tenant_id: Parent tenant ID
po_id: Purchase order ID to approve
approved_by_user_id: User ID performing approval
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
Updated purchase order
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.post(
f"procurement/internal-transfers/{po_id}/approve",
data={
"approved_by_user_id": approved_by_user_id
},
tenant_id=parent_tenant_id
)
if response:
logger.info("Approved internal purchase order",
parent_tenant_id=parent_tenant_id,
po_id=po_id)
2025-10-30 21:08:07 +01:00
return response
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error approving internal purchase order",
parent_tenant_id=parent_tenant_id,
po_id=po_id,
error=str(e))
2025-10-30 21:08:07 +01:00
return None
2025-11-30 09:12:40 +01:00
async def get_internal_transfer_history(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
parent_tenant_id: Optional[str] = None,
child_tenant_id: Optional[str] = None,
start_date: Optional[date] = None,
end_date: Optional[date] = None
) -> Optional[List[Dict[str, Any]]]:
2025-10-30 21:08:07 +01:00
"""
2025-11-30 09:12:40 +01:00
Get internal transfer history with optional filtering
2025-10-30 21:08:07 +01:00
Args:
2025-11-30 09:12:40 +01:00
tenant_id: Tenant ID (either parent or child)
parent_tenant_id: Filter by specific parent tenant
child_tenant_id: Filter by specific child tenant
start_date: Filter by start date
end_date: Filter by end date
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
List of internal transfer records
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
params = {}
if parent_tenant_id:
params["parent_tenant_id"] = parent_tenant_id
if child_tenant_id:
params["child_tenant_id"] = child_tenant_id
if start_date:
params["start_date"] = start_date.isoformat()
if end_date:
params["end_date"] = end_date.isoformat()
2025-10-30 21:08:07 +01:00
2025-11-30 09:12:40 +01:00
response = await self.get(
"procurement/internal-transfers/history",
params=params,
tenant_id=tenant_id
)
if response:
logger.info("Retrieved internal transfer history",
tenant_id=tenant_id,
count=len(response))
return response if response else []
2025-10-30 21:08:07 +01:00
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting internal transfer history",
tenant_id=tenant_id,
error=str(e))
return []
# ================================================================
# PROCUREMENT PLAN ENDPOINTS
# ================================================================
2025-10-30 21:08:07 +01:00
2025-11-30 09:12:40 +01:00
async def get_procurement_plan(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
plan_id: str
) -> Optional[Dict[str, Any]]:
2025-10-30 21:08:07 +01:00
"""
2025-11-30 09:12:40 +01:00
Get a specific procurement plan
2025-10-30 21:08:07 +01:00
Args:
tenant_id: Tenant ID
2025-11-30 09:12:40 +01:00
plan_id: Procurement plan ID
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
Procurement plan details
2025-10-30 21:08:07 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.get(
f"procurement/plans/{plan_id}",
tenant_id=tenant_id
)
if response:
logger.info("Retrieved procurement plan",
tenant_id=tenant_id,
plan_id=plan_id)
2025-10-30 21:08:07 +01:00
return response
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting procurement plan",
tenant_id=tenant_id,
plan_id=plan_id,
error=str(e))
2025-10-30 21:08:07 +01:00
return None
2025-11-30 09:12:40 +01:00
async def get_procurement_plans(
2025-10-30 21:08:07 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
date_from: Optional[date] = None,
date_to: Optional[date] = None,
status: Optional[str] = None
) -> Optional[List[Dict[str, Any]]]:
2025-10-30 21:08:07 +01:00
"""
2025-11-30 09:12:40 +01:00
Get procurement plans with optional filtering
2025-10-30 21:08:07 +01:00
Args:
tenant_id: Tenant ID
2025-11-30 09:12:40 +01:00
date_from: Start date for filtering
date_to: End date for filtering
status: Status filter
2025-10-30 21:08:07 +01:00
Returns:
2025-11-30 09:12:40 +01:00
List of procurement plan dictionaries
2025-10-30 21:08:07 +01:00
"""
try:
params = {}
2025-11-30 09:12:40 +01:00
if date_from:
params["date_from"] = date_from.isoformat()
if date_to:
params["date_to"] = date_to.isoformat()
if status:
params["status"] = status
2025-10-30 21:08:07 +01:00
2025-11-30 09:12:40 +01:00
response = await self.get(
"procurement/plans",
params=params,
tenant_id=tenant_id
)
if response:
logger.info("Retrieved procurement plans",
tenant_id=tenant_id,
count=len(response))
return response if response else []
2025-10-30 21:08:07 +01:00
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting procurement plans",
tenant_id=tenant_id,
error=str(e))
return []
2025-11-05 13:34:56 +01:00
# ================================================================
2025-11-30 09:12:40 +01:00
# SUPPLIER ENDPOINTS
2025-11-05 13:34:56 +01:00
# ================================================================
2025-11-30 09:12:40 +01:00
async def get_suppliers(
2025-11-05 13:34:56 +01:00
self,
2025-11-30 09:12:40 +01:00
tenant_id: str
) -> Optional[List[Dict[str, Any]]]:
2025-11-05 13:34:56 +01:00
"""
2025-11-30 09:12:40 +01:00
Get suppliers for a tenant
2025-11-05 13:34:56 +01:00
Args:
2025-11-30 09:12:40 +01:00
tenant_id: Tenant ID
2025-11-05 13:34:56 +01:00
Returns:
2025-11-30 09:12:40 +01:00
List of supplier dictionaries
2025-11-05 13:34:56 +01:00
"""
try:
2025-11-30 09:12:40 +01:00
response = await self.get(
"procurement/suppliers",
tenant_id=tenant_id
)
if response:
logger.info("Retrieved suppliers",
tenant_id=tenant_id,
count=len(response))
return response if response else []
2025-11-05 13:34:56 +01:00
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting suppliers",
tenant_id=tenant_id,
error=str(e))
return []
2025-11-05 13:34:56 +01:00
2025-11-30 09:12:40 +01:00
async def get_supplier(
2025-11-05 13:34:56 +01:00
self,
tenant_id: str,
2025-11-30 09:12:40 +01:00
supplier_id: str
2025-11-05 13:34:56 +01:00
) -> Optional[Dict[str, Any]]:
"""
2025-11-30 09:12:40 +01:00
Get specific supplier details
2025-11-05 13:34:56 +01:00
Args:
2025-11-30 09:12:40 +01:00
tenant_id: Tenant ID
supplier_id: Supplier ID
2025-11-05 13:34:56 +01:00
Returns:
2025-11-30 09:12:40 +01:00
Supplier details
2025-11-05 13:34:56 +01:00
"""
try:
Fix critical bugs and standardize service integrations Critical Fixes: - Orchestrator: Add missing OrchestrationStatus import (fixes HTTP 500 during demo clone) - Procurement: Migrate from custom cache utils to shared Redis utils - Suppliers: Use proper Settings for Redis configuration with TLS/auth - Recipes/Suppliers clients: Fix endpoint paths (remove duplicate path segments) - Procurement client: Use suppliers service directly for supplier details Details: 1. services/orchestrator/app/api/internal_demo.py: - Added OrchestrationStatus import to fix cloning error - This was causing HTTP 500 errors during demo session cloning 2. services/procurement/app/api/purchase_orders.py + service: - Replaced app.utils.cache with shared.redis_utils - Standardizes caching across all services - Removed custom cache utilities (deleted app/utils/cache.py) 3. services/suppliers/app/consumers/alert_event_consumer.py: - Use Settings().REDIS_URL instead of os.getenv - Ensures proper Redis connection with TLS and authentication 4. shared/clients/recipes_client.py: - Fixed endpoint paths: recipes/recipes/{id} → recipes/{id} - Applied to all recipe methods (by_id, by_products, instructions, yield) 5. shared/clients/suppliers_client.py: - Fixed endpoint path: suppliers/suppliers/{id} → suppliers/{id} 6. shared/clients/procurement_client.py: - get_supplier_by_id now uses SuppliersServiceClient directly - Removes incorrect call to procurement service for supplier details Impact: - Demo session cloning now works without orchestrator errors ✅ - Consistent Redis usage across all services - Correct service boundaries (suppliers data from suppliers service) - Clean client endpoint paths 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-16 11:33:22 +01:00
# Use suppliers service to get supplier details
from shared.clients.suppliers_client import SuppliersServiceClient
suppliers_client = SuppliersServiceClient(self.config)
response = await suppliers_client.get_supplier_by_id(tenant_id, supplier_id)
2025-11-30 09:12:40 +01:00
if response:
logger.info("Retrieved supplier details",
tenant_id=tenant_id,
supplier_id=supplier_id)
return response
2025-11-05 13:34:56 +01:00
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Error getting supplier details",
tenant_id=tenant_id,
supplier_id=supplier_id,
error=str(e))
2025-11-05 13:34:56 +01:00
return None
# ================================================================
2025-11-30 09:12:40 +01:00
# UTILITIES
# ================================================================
2025-11-30 09:12:40 +01:00
async def health_check(self) -> bool:
"""Check if procurement service is healthy"""
try:
2025-11-30 09:12:40 +01:00
# Use base health check method
response = await self.get("health")
return response is not None
except Exception as e:
2025-11-30 09:12:40 +01:00
logger.error("Procurement service health check failed", error=str(e))
return False
2025-12-13 23:57:54 +01:00
# ================================================================
# INTERNAL TRIGGER METHODS
# ================================================================
async def trigger_delivery_tracking_internal(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Trigger delivery tracking for a tenant (internal service use only).
This method calls the internal endpoint which is protected by X-Internal-Service header.
Args:
tenant_id: Tenant ID to trigger delivery tracking for
Returns:
Dict with trigger results or None if failed
"""
try:
# Call internal endpoint via gateway using tenant-scoped URL pattern
# Endpoint: /api/v1/tenants/{tenant_id}/procurement/internal/delivery-tracking/trigger
result = await self._make_request(
method="POST",
endpoint="procurement/internal/delivery-tracking/trigger",
tenant_id=tenant_id,
data={},
headers={"X-Internal-Service": "demo-session"}
)
if result:
logger.info(
"Delivery tracking triggered successfully via internal endpoint",
tenant_id=tenant_id,
alerts_generated=result.get("alerts_generated", 0)
)
else:
logger.warning(
"Delivery tracking internal endpoint returned no result",
tenant_id=tenant_id
)
return result
except Exception as e:
logger.error(
"Error triggering delivery tracking via internal endpoint",
tenant_id=tenant_id,
error=str(e)
)
return None
# ================================================================
# INTERNAL AI INSIGHTS METHODS
# ================================================================
async def trigger_price_insights_internal(
self,
tenant_id: str
) -> Optional[Dict[str, Any]]:
"""
Trigger price forecasting insights for a tenant (internal service use only).
This method calls the internal endpoint which is protected by X-Internal-Service header.
Args:
tenant_id: Tenant ID to trigger insights for
Returns:
Dict with trigger results or None if failed
"""
try:
result = await self._make_request(
method="POST",
endpoint="procurement/internal/ml/generate-price-insights",
tenant_id=tenant_id,
data={"tenant_id": tenant_id},
headers={"X-Internal-Service": "demo-session"}
)
if result:
logger.info(
"Price insights triggered successfully via internal endpoint",
tenant_id=tenant_id,
insights_posted=result.get("insights_posted", 0)
)
else:
logger.warning(
"Price insights internal endpoint returned no result",
tenant_id=tenant_id
)
return result
except Exception as e:
logger.error(
"Error triggering price insights via internal endpoint",
tenant_id=tenant_id,
error=str(e)
)
return None
2025-11-30 09:12:40 +01:00
# Factory function for dependency injection
def create_procurement_client(config: BaseServiceSettings, service_name: str = "unknown") -> ProcurementServiceClient:
"""Create procurement service client instance"""
return ProcurementServiceClient(config, service_name)