Improve frontend panel de control

This commit is contained in:
Urtzi Alfaro
2025-11-20 22:10:16 +01:00
parent 80298b61b2
commit 2ee94fb4b1
9 changed files with 117 additions and 74 deletions

View File

@@ -390,15 +390,30 @@ class DashboardService:
# Calculate urgency based on required delivery date
urgency = self._calculate_po_urgency(po)
# Get reasoning_data or create default
reasoning_data = po.get("reasoning_data") or {
"type": "low_stock_detection",
"parameters": {
"supplier_name": po.get('supplier_name', 'Unknown'),
"product_names": ["Items"],
"days_until_stockout": 7
# Get reasoning_data or create intelligent fallback from PO items
reasoning_data = po.get("reasoning_data")
if not reasoning_data:
# Extract product names from PO line items for better UX
product_names = []
items = po.get("items", [])
for item in items[:5]: # Limit to first 5 items for readability
product_name = item.get("product_name") or item.get("name")
if product_name:
product_names.append(product_name)
# If no items or product names found, use generic fallback
if not product_names:
product_names = ["Items"]
# Create fallback reasoning_data
reasoning_data = {
"type": "low_stock_detection",
"parameters": {
"supplier_name": po.get('supplier_name', 'Unknown'),
"product_names": product_names,
"days_until_stockout": 7
}
}
}
# Get reasoning type and convert to i18n key
reasoning_type = reasoning_data.get('type', 'inventory_replenishment')

View File

@@ -168,6 +168,9 @@ class PurchaseOrderResponse(PurchaseOrderBase):
# Additional information
notes: Optional[str] = None
# AI/ML reasoning for procurement decisions (JTBD dashboard support)
reasoning_data: Optional[Dict[str, Any]] = None
# Audit fields
created_at: datetime
updated_at: datetime

View File

@@ -137,7 +137,8 @@ async def create_purchase_order(
try:
# Get product names from items_data
items_list = items_data or []
product_names = [item.get('product_name', f"Product {i+1}") for i, item in enumerate(items_list)]
# CRITICAL FIX: Use 'name' key, not 'product_name', to match items_data structure
product_names = [item.get('name', item.get('product_name', f"Product {i+1}")) for i, item in enumerate(items_list)]
if not product_names:
product_names = ["Demo Product"]
@@ -192,8 +193,10 @@ async def create_purchase_order(
if reasoning_data:
try:
po.reasoning_data = reasoning_data
except Exception:
pass # Columns don't exist yet
logger.debug(f"Set reasoning_data for PO {po_number}: {reasoning_data.get('type', 'unknown')}")
except Exception as e:
logger.warning(f"Failed to set reasoning_data for PO {po_number}: {e}")
pass # Column might not exist yet
# Set approval data if approved
if status in [PurchaseOrderStatus.approved, PurchaseOrderStatus.sent_to_supplier,