New alert service

This commit is contained in:
Urtzi Alfaro
2025-12-05 20:07:01 +01:00
parent 1fe3a73549
commit 667e6e0404
393 changed files with 26002 additions and 61033 deletions

View File

@@ -138,7 +138,8 @@ class ProcurementServiceClient(BaseServiceClient):
async def get_pending_purchase_orders(
self,
tenant_id: str,
limit: int = 50
limit: int = 50,
enrich_supplier: bool = True
) -> Optional[List[Dict[str, Any]]]:
"""
Get pending purchase orders
@@ -146,6 +147,8 @@ class ProcurementServiceClient(BaseServiceClient):
Args:
tenant_id: Tenant ID
limit: Maximum number of results
enrich_supplier: Whether to include supplier details (default: True)
Set to False for faster queries when supplier data will be fetched separately
Returns:
List of pending purchase orders
@@ -153,14 +156,19 @@ class ProcurementServiceClient(BaseServiceClient):
try:
response = await self.get(
"procurement/purchase-orders",
params={"status": "pending_approval", "limit": limit},
params={
"status": "pending_approval",
"limit": limit,
"enrich_supplier": enrich_supplier
},
tenant_id=tenant_id
)
if response:
logger.info("Retrieved pending purchase orders",
tenant_id=tenant_id,
count=len(response))
count=len(response),
enriched=enrich_supplier)
return response if response else []
except Exception as e:
logger.error("Error getting pending purchase orders",
@@ -168,6 +176,60 @@ class ProcurementServiceClient(BaseServiceClient):
error=str(e))
return []
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 []
# ================================================================
# INTERNAL TRANSFER ENDPOINTS (NEW FOR ENTERPRISE TIER)
# ================================================================