demo seed change 4

This commit is contained in:
Urtzi Alfaro
2025-12-14 19:05:37 +01:00
parent 4ae5356ad1
commit 82f9622411
16 changed files with 532 additions and 55 deletions

View File

@@ -45,7 +45,7 @@ class SalesServiceClient(BaseServiceClient):
if product_id:
params["product_id"] = product_id
result = await self.get("sales/sales", tenant_id=tenant_id, params=params)
result = await self.get("sales", tenant_id=tenant_id, params=params)
# Handle both list and dict responses
if result is None:

View File

@@ -6,7 +6,7 @@
"po_number": "PO-LATE-0001",
"supplier_id": "40000000-0000-0000-0000-000000000001",
"order_date": "BASE_TS - 1d",
"status": "pending_approval",
"status": "confirmed",
"priority": "high",
"required_delivery_date": "BASE_TS - 4h",
"estimated_delivery_date": "BASE_TS - 4h",
@@ -60,7 +60,7 @@
"po_number": "PO-UPCOMING-0001",
"supplier_id": "40000000-0000-0000-0000-000000000002",
"order_date": "BASE_TS - 1h",
"status": "pending_approval",
"status": "confirmed",
"priority": "medium",
"required_delivery_date": "BASE_TS + 2h30m",
"estimated_delivery_date": "BASE_TS + 2h30m",
@@ -208,7 +208,7 @@
"tenant_id": "a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6",
"po_number": "PO-2025-003",
"supplier_id": "40000000-0000-0000-0000-000000000003",
"status": "approved",
"status": "pending_approval",
"priority": "high",
"subtotal": 490.0,
"tax_amount": 102.9,
@@ -221,18 +221,17 @@
"delivery_contact": "Pedro Calidad",
"delivery_phone": "+34 910 123 456",
"requires_approval": true,
"auto_approved": true,
"auto_approval_rule_id": "10000000-0000-0000-0000-000000000001",
"approved_by": "50000000-0000-0000-0000-000000000006",
"notes": "Pedido urgente para nueva línea de productos ecológicos - Auto-aprobado por IA",
"notes": "Pedido urgente para nueva línea de productos ecológicos - Requiere aprobación del gerente",
"reasoning_data": {
"type": "supplier_contract",
"parameters": {
"supplier_name": "Productos Ecológicos del Norte",
"product_names": ["Organic ingredients"],
"product_names": ["Harina de Espelta Ecológica"],
"product_count": 1,
"contract_terms": "certified_supplier",
"contract_quantity": 450.0
"contract_quantity": 200.0,
"current_stock": 186.36,
"reorder_point": 50.0
},
"consequence": {
"type": "quality_assurance",
@@ -241,17 +240,14 @@
},
"metadata": {
"trigger_source": "manual",
"ai_assisted": true,
"auto_approved": true,
"auto_approval_rule_id": "10000000-0000-0000-0000-000000000001"
"ai_assisted": true
}
},
"created_by": "50000000-0000-0000-0000-000000000005",
"order_date": "BASE_TS - 3d",
"required_delivery_date": "BASE_TS + 1d",
"estimated_delivery_date": "BASE_TS + 2d",
"expected_delivery_date": "BASE_TS + 2d",
"approved_at": "BASE_TS - 2d"
"expected_delivery_date": "BASE_TS + 2d"
},
{
"id": "50000000-0000-0000-0000-000000000004",
@@ -449,6 +445,55 @@
"estimated_delivery_date": "BASE_TS + 0.25d",
"expected_delivery_date": "BASE_TS + 0.25d",
"sent_to_supplier_at": "BASE_TS - 0.5d"
},
{
"id": "50000000-0000-0000-0000-000000000008",
"tenant_id": "a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6",
"po_number": "PO-2025-008",
"supplier_id": "40000000-0000-0000-0000-000000000004",
"order_date": "BASE_TS - 0.25d",
"status": "pending_approval",
"priority": "medium",
"required_delivery_date": "BASE_TS + 2d",
"estimated_delivery_date": "BASE_TS + 2d",
"expected_delivery_date": "BASE_TS + 2d",
"subtotal": 180.0,
"tax_amount": 37.8,
"shipping_cost": 12.0,
"discount_amount": 0.0,
"total_amount": 229.8,
"currency": "EUR",
"delivery_address": "Calle Panadería, 45, 28001 Madrid",
"delivery_instructions": "Entrega en almacén seco - Zona A",
"delivery_contact": "Carlos Almacén",
"delivery_phone": "+34 910 123 456",
"requires_approval": true,
"notes": "Reposición de ingredientes básicos - Stock bajo en azúcar",
"reasoning_data": {
"type": "low_stock_detection",
"parameters": {
"supplier_name": "Distribuciones Alimentarias del Sur",
"product_names": ["Azúcar Blanco Refinado"],
"product_count": 1,
"current_stock": 24.98,
"required_stock": 120.0,
"days_until_stockout": 3,
"threshold_percentage": 66,
"stock_percentage": 20
},
"consequence": {
"type": "stockout_risk",
"severity": "medium",
"impact_days": 3,
"affected_products": ["Croissants", "Napolitanas", "Pan Dulce"],
"estimated_lost_orders": 15
},
"metadata": {
"trigger_source": "orchestrator_auto",
"ai_assisted": true
}
},
"created_by": "50000000-0000-0000-0000-000000000005"
}
],
"purchase_order_items": [
@@ -693,6 +738,21 @@
"line_total": 71.2,
"received_quantity": 0.0,
"remaining_quantity": 8.0
},
{
"id": "51000000-0000-0000-0000-0000000000a7",
"tenant_id": "a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6",
"purchase_order_id": "50000000-0000-0000-0000-000000000008",
"inventory_product_id": "10000000-0000-0000-0000-000000000032",
"product_name": "Azúcar Blanco Refinado",
"product_code": "BAS-AZU-002",
"ordered_quantity": 200.0,
"unit_of_measure": "kilograms",
"unit_price": 0.9,
"line_total": 180.0,
"received_quantity": 0.0,
"remaining_quantity": 200.0,
"notes": "Reposición stock bajo - Nivel crítico detectado"
}
]
}

View File

@@ -9,6 +9,7 @@ import logging
import logging.config
import os
import sys
import resource
from typing import Dict, Any
def setup_logging(service_name: str, log_level: str = "INFO",
@@ -23,16 +24,37 @@ def setup_logging(service_name: str, log_level: str = "INFO",
enable_file: Whether to enable file logging
"""
# Check file descriptor limits
try:
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
if soft_limit < 1024:
print(f"Warning: Low file descriptor limit ({soft_limit}). Consider increasing with 'ulimit -n'")
if soft_limit < 256:
print("Critical: File descriptor limit is very low. File logging may fail.")
enable_file = False
except Exception:
# resource module might not be available on all platforms
pass
# Create logs directory if it doesn't exist and file logging is enabled
log_dir = "/var/log"
if enable_file:
try:
os.makedirs(log_dir, exist_ok=True)
except PermissionError:
# First try to create/write to /var/log
test_file = os.path.join(log_dir, f".{service_name}_test")
with open(test_file, 'w') as f:
f.write("test")
os.remove(test_file)
except (PermissionError, OSError):
# Fallback to local directory if can't write to /var/log
log_dir = "./logs"
os.makedirs(log_dir, exist_ok=True)
print(f"Warning: Could not write to /var/log, using {log_dir}")
try:
os.makedirs(log_dir, exist_ok=True)
except Exception as e:
print(f"Warning: Could not create log directory {log_dir}: {e}")
enable_file = False # Disable file logging if we can't create directory
# Define formatters
formatters = {
@@ -70,14 +92,25 @@ def setup_logging(service_name: str, log_level: str = "INFO",
# Add file handler if enabled
if enable_file:
handlers["file"] = {
"class": "logging.FileHandler",
"level": log_level,
"formatter": "detailed",
"filename": f"{log_dir}/{service_name}.log",
"mode": "a",
"encoding": "utf-8"
}
try:
# Test if we can actually write to the log file location
test_filename = f"{log_dir}/{service_name}.log"
test_dir = os.path.dirname(test_filename)
if not os.access(test_dir, os.W_OK):
print(f"Warning: Cannot write to log directory {test_dir}, disabling file logging")
enable_file = False
else:
handlers["file"] = {
"class": "logging.FileHandler",
"level": log_level,
"formatter": "detailed",
"filename": test_filename,
"mode": "a",
"encoding": "utf-8"
}
except Exception as e:
print(f"Warning: Could not configure file handler: {e}")
enable_file = False
# Add logstash handler if in production
logstash_host = os.getenv("LOGSTASH_HOST")
@@ -141,6 +174,10 @@ def setup_logging(service_name: str, log_level: str = "INFO",
logging.config.dictConfig(config)
logger = logging.getLogger(__name__)
logger.info(f"Logging configured for {service_name} at level {log_level}")
if enable_file:
logger.info(f"File logging enabled at {log_dir}/{service_name}.log")
else:
logger.info("File logging disabled")
except Exception as e:
# Fallback to basic logging if configuration fails
logging.basicConfig(
@@ -151,4 +188,10 @@ def setup_logging(service_name: str, log_level: str = "INFO",
logger = logging.getLogger(__name__)
logger.error(f"Failed to configure advanced logging for {service_name}: {e}")
logger.info(f"Using basic logging configuration for {service_name}")
# Additional debugging for file handler issues
if "file" in str(e).lower() or "handler" in str(e).lower():
logger.error(f"File handler configuration failed. Check permissions for {log_dir}")
logger.error(f"Current working directory: {os.getcwd()}")
logger.error(f"Attempting to write to: {log_dir}/{service_name}.log")