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

47 lines
1.5 KiB
Python

from app.models import SessionLocal, DitRecord, OrderRecord
from app.services.fuzzy_matcher import normalize_pn_for_matching, normalize_id
import pandas as pd
db = SessionLocal()
try:
print("=== DIT Record Info ===")
# DIT Project: PJQ5514S6C-AU R2 002A1
target_pn = "PJQ5514S6C-AU R2 002A1"
target_norm_pn = normalize_pn_for_matching(target_pn)
dits = db.query(DitRecord).filter(DitRecord.pn.like('%PJQ5514S6C%')).all()
if not dits:
print("No DIT found for PJQ5514S6C")
for d in dits:
print(f"DIT ID: {d.id}")
print(f" Op ID: {d.op_id}")
print(f" Customer: {d.customer}")
print(f" PN: {d.pn} (Norm: {normalize_pn_for_matching(d.pn)})")
print(f" ERP: {d.erp_account}")
print(f" Date: {d.date}")
print("\n=== Order Records Info ===")
orders = db.query(OrderRecord).filter(OrderRecord.pn.like('%PJQ5514S6C%')).all()
print(f"Total orders found: {len(orders)}")
# Group by date to see range
if orders:
df = pd.DataFrame([{
'id': o.id,
'order_no': o.order_no,
'cust_id': o.cust_id,
'pn': o.pn,
'date': o.date
} for o in orders])
print("\nOrder Date Summary:")
print(df['date'].value_counts().sort_index())
print("\nDetail of first 5 orders:")
for o in orders[:5]:
print(f" ID: {o.id}, No: {o.order_no}, CustID: {o.cust_id}, PN: {o.pn}, Date: {o.date}")
except Exception as e:
print(f"Error: {e}")
finally:
db.close()