fix: Correct variable references in PO seed script
Fixed 'items' is not defined error in demo seed script: - Changed 'items' references to 'items_data' (the function parameter) - Updated product_names extraction to use dict.get() for safety - Fixed create_po_reasoning_supplier_contract call to use correct parameters (contract_quantity instead of trust_score) This resolves the warnings about failed reasoning_data generation during purchase order seeding.
This commit is contained in:
@@ -128,10 +128,11 @@ async def create_purchase_order(
|
|||||||
reasoning_data = None
|
reasoning_data = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get product names from items
|
# Get product names from items_data
|
||||||
product_names = [item.product_name for item in items if hasattr(item, 'product_name')]
|
items_list = items_data or []
|
||||||
|
product_names = [item.get('product_name', f"Product {i+1}") for i, item in enumerate(items_list)]
|
||||||
if not product_names:
|
if not product_names:
|
||||||
product_names = [f"Product {i+1}" for i in range(len(items))]
|
product_names = ["Demo Product"]
|
||||||
|
|
||||||
if status == PurchaseOrderStatus.pending_approval:
|
if status == PurchaseOrderStatus.pending_approval:
|
||||||
# Low stock detection reasoning
|
# Low stock detection reasoning
|
||||||
@@ -151,8 +152,8 @@ async def create_purchase_order(
|
|||||||
reasoning_data = create_po_reasoning_supplier_contract(
|
reasoning_data = create_po_reasoning_supplier_contract(
|
||||||
supplier_name=supplier.name,
|
supplier_name=supplier.name,
|
||||||
product_names=product_names,
|
product_names=product_names,
|
||||||
contract_terms=f"Auto-approval threshold: €500",
|
contract_terms="monthly",
|
||||||
trust_score=float(supplier.trust_score) if hasattr(supplier, 'trust_score') else 0.85
|
contract_quantity=float(total_amount)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to generate reasoning_data: {e}")
|
logger.warning(f"Failed to generate reasoning_data: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user