Files
SalesPipeline/backend/debug_matching.py
2026-01-27 19:08:46 +08:00

50 lines
1.4 KiB
Python

from app.routers.lab import fetch_orders_light, normalize_id, normalize_customer_name, normalize_pn_for_matching
from app.models import get_db
db = next(get_db())
target_cust_name = "緯創資通"
target_id = "177100"
target_pn = "PEC3205M1QR100201"
print(f"Targeting: Name={target_cust_name}, ID={target_id}, PN={target_pn}")
print("Fetching orders...")
orders = fetch_orders_light(db, start_date="2025-01-01")
found_cust = 0
found_id = 0
found_pn = 0
matching_orders = []
for o in orders:
n_name = o['norm_cust_name']
c_id = o['clean_cust_id']
c_pn = o['clean_pn']
if target_cust_name in n_name:
found_cust += 1
if target_id == c_id:
found_id += 1
if target_pn == c_pn:
found_pn += 1
print("!!! PN MATCH FOUND !!!")
print(f"Order Cust: '{o['customer']}'")
print(f"Order Norm Cust: '{o['norm_cust_name']}'")
print(f"Order ID: '{o['cust_id']}'")
print("Full Order:", o)
if target_id == c_id and target_pn == c_pn:
matching_orders.append(o)
elif target_cust_name == n_name and target_pn == c_pn:
matching_orders.append(o)
print(f"Orders with similar Name: {found_cust}")
print(f"Orders with Exact ID: {found_id}")
print(f"Orders with Exact PN: {found_pn}")
print(f"Exact Matches Found in List: {len(matching_orders)}")
if matching_orders:
print("Example Match:", matching_orders[0])