Răsfoiți Sursa

debug: added order update logging and price syncing

unknown 1 zi în urmă
părinte
comite
eb79a43100
1 a modificat fișierele cu 5 adăugiri și 1 ștergeri
  1. 5 1
      backend/routers/orders.py

+ 5 - 1
backend/routers/orders.py

@@ -258,7 +258,7 @@ async def get_admin_orders(
     where_sql = f"WHERE {' AND '.join(where_clauses)}" if where_clauses else ""
 
     query = f"""
-    SELECT o.*, u.can_chat, o.total_price AS invoice_amount,
+    SELECT o.*, u.can_chat, COALESCE(o.total_price, o.estimated_price) AS invoice_amount,
            (SELECT count(*) FROM order_messages om WHERE om.order_id = o.id AND om.is_from_admin = FALSE AND om.is_read = FALSE) as unread_count,
            GROUP_CONCAT(IF(f.id IS NOT NULL, JSON_OBJECT('id', f.id, 'filename', f.filename, 'file_path', f.file_path, 'file_size', f.file_size, 'quantity', f.quantity, 'preview_path', f.preview_path, 'print_time', f.print_time, 'filament_g', f.filament_g), NULL)) as files
     FROM orders o
@@ -289,6 +289,7 @@ async def update_order(
     background_tasks: BackgroundTasks,
     admin: dict = Depends(require_admin)
 ):
+    print(f"DEBUG: update_order {order_id} - payload: {data.model_dump(exclude_unset=True)}")
     order_info = db.execute_query("SELECT * FROM orders WHERE id = %s", (order_id,))
     if not order_info: raise HTTPException(status_code=404, detail="Order not found")
 
@@ -339,6 +340,9 @@ async def update_order(
     if data.total_price is not None:
         update_fields.append("total_price = %s")
         params.append(data.total_price)
+        # Sync estimated_price as well to ensure display consistency in all views
+        update_fields.append("estimated_price = %s")
+        params.append(data.total_price)
     
     if data.material_id is not None:
         update_fields.append("material_id = %s")