Analysis scripts to match GoMag orders with Oracle invoices by date/client/total, then compare line items by price to discover SKU → id_articol mappings. Generates SQL for nom_articole codmat updates and CSV for ARTICOLE_TERTI repackaging/set mappings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
980 B
Python
31 lines
980 B
Python
import sqlite3, sys
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
|
|
db = sqlite3.connect(r'C:\gomag-vending\api\data\import.db')
|
|
c = db.cursor()
|
|
|
|
c.execute("SELECT COUNT(*), MIN(order_date), MAX(order_date) FROM orders")
|
|
total, min_d, max_d = c.fetchone()
|
|
print(f"Total orders: {total} (from {min_d} to {max_d})")
|
|
|
|
c.execute("SELECT status, COUNT(*) FROM orders GROUP BY status ORDER BY COUNT(*) DESC")
|
|
print("\nBy status:")
|
|
for r in c:
|
|
print(f" {r[0]:20s} {r[1]:5d}")
|
|
|
|
c.execute("SELECT COUNT(*) FROM orders WHERE status IN ('IMPORTED','ALREADY_IMPORTED')")
|
|
print(f"\nImported (matchable): {c.fetchone()[0]}")
|
|
|
|
c.execute("SELECT COUNT(*) FROM order_items")
|
|
print(f"Total order_items: {c.fetchone()[0]}")
|
|
|
|
c.execute("""
|
|
SELECT COUNT(DISTINCT oi.sku)
|
|
FROM order_items oi
|
|
JOIN orders o ON oi.order_number = o.order_number
|
|
WHERE o.status IN ('IMPORTED','ALREADY_IMPORTED')
|
|
""")
|
|
print(f"Unique SKUs in imported orders: {c.fetchone()[0]}")
|
|
|
|
db.close()
|