add: scripts for invoice-order matching and SKU discovery
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>
This commit is contained in:
61
scripts/check_imported.py
Normal file
61
scripts/check_imported.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Check imported orders in SQLite and Oracle — what needs to be deleted"""
|
||||
import sys, sqlite3, oracledb, os
|
||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
||||
|
||||
os.environ['PATH'] = r'C:\app\Server\product\18.0.0\dbhomeXE\bin' + ';' + os.environ.get('PATH','')
|
||||
oracledb.init_oracle_client()
|
||||
|
||||
db = sqlite3.connect(r'C:\gomag-vending\api\data\import.db')
|
||||
db.row_factory = sqlite3.Row
|
||||
c = db.cursor()
|
||||
|
||||
# Get imported orders with id_comanda
|
||||
c.execute("""
|
||||
SELECT order_number, customer_name, id_comanda, id_partener, order_date, order_total
|
||||
FROM orders
|
||||
WHERE status = 'IMPORTED' AND id_comanda IS NOT NULL
|
||||
ORDER BY order_date
|
||||
""")
|
||||
imported = [dict(r) for r in c.fetchall()]
|
||||
db.close()
|
||||
|
||||
print(f"Imported orders in SQLite: {len(imported)}")
|
||||
|
||||
# Check Oracle status
|
||||
conn = oracledb.connect(user='VENDING', password='ROMFASTSOFT', dsn='ROA')
|
||||
cur = conn.cursor()
|
||||
|
||||
print(f"\n{'ORDER_NR':>12s} {'ID_CMD':>8s} {'SQLITE_CLIENT':30s} {'ROA_PARTNER':30s} {'ROA_STERS':>9s} {'FACTURAT':>8s} {'DATA':>12s}")
|
||||
for o in imported:
|
||||
id_cmd = o['id_comanda']
|
||||
|
||||
# Check COMENZI
|
||||
cur.execute("""
|
||||
SELECT c.sters, p.denumire, p.prenume,
|
||||
(SELECT COUNT(*) FROM vanzari v WHERE v.id_comanda = c.id_comanda AND v.sters = 0) as nr_facturi
|
||||
FROM comenzi c
|
||||
LEFT JOIN nom_parteneri p ON c.id_part = p.id_part
|
||||
WHERE c.id_comanda = :1
|
||||
""", [id_cmd])
|
||||
row = cur.fetchone()
|
||||
if row:
|
||||
sters = row[0]
|
||||
partner = ((row[1] or '') + ' ' + (row[2] or '')).strip()
|
||||
nr_fact = row[3]
|
||||
print(f"{o['order_number']:>12s} {id_cmd:>8d} {(o['customer_name'] or '')[:30]:30s} {partner[:30]:30s} {'DA' if sters else 'NU':>9s} {nr_fact:>8d} {str(o['order_date'])[:10]:>12s}")
|
||||
else:
|
||||
print(f"{o['order_number']:>12s} {id_cmd:>8d} {(o['customer_name'] or '')[:30]:30s} {'NOT FOUND':30s}")
|
||||
|
||||
# Check if there's a delete/sters mechanism
|
||||
print(f"\n--- COMENZI table columns for delete ---")
|
||||
cur.execute("SELECT column_name FROM all_tab_columns WHERE table_name='COMENZI' AND owner='VENDING' AND column_name IN ('STERS','ID_UTILS','DATAORAS') ORDER BY column_id")
|
||||
for r in cur:
|
||||
print(f" {r[0]}")
|
||||
|
||||
# Check comenzi_detalii
|
||||
cur.execute("SELECT column_name FROM all_tab_columns WHERE table_name='COMENZI_DETALII' AND owner='VENDING' ORDER BY column_id")
|
||||
print(f"\n--- COMENZI_DETALII columns ---")
|
||||
for r in cur:
|
||||
print(f" {r[0]}")
|
||||
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user