feat(sync): already_imported tracking, invoice cache, path fixes, remove vfp
- Track already_imported/new_imported counts separately in sync_runs and surface them in status API + dashboard last-run card - Cache invoice data in SQLite orders table (factura_* columns); dashboard falls back to Oracle only for uncached imported orders - Resolve JSON_OUTPUT_DIR and SQLITE_DB_PATH relative to known anchored roots in config.py, independent of CWD (fixes WSL2 start) - Use single Oracle connection for entire validation phase (perf) - Batch upsert web_products instead of one-by-one - Remove stale VFP scripts (replaced by gomag-vending.prg workflow) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -73,7 +73,9 @@ CREATE TABLE IF NOT EXISTS sync_runs (
|
||||
skipped INTEGER DEFAULT 0,
|
||||
errors INTEGER DEFAULT 0,
|
||||
json_files INTEGER DEFAULT 0,
|
||||
error_message TEXT
|
||||
error_message TEXT,
|
||||
already_imported INTEGER DEFAULT 0,
|
||||
new_imported INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
@@ -95,7 +97,13 @@ CREATE TABLE IF NOT EXISTS orders (
|
||||
shipping_name TEXT,
|
||||
billing_name TEXT,
|
||||
payment_method TEXT,
|
||||
delivery_method TEXT
|
||||
delivery_method TEXT,
|
||||
factura_serie TEXT,
|
||||
factura_numar TEXT,
|
||||
factura_total_fara_tva REAL,
|
||||
factura_total_tva REAL,
|
||||
factura_total_cu_tva REAL,
|
||||
invoice_checked_at TEXT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_orders_status ON orders(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_orders_date ON orders(order_date);
|
||||
@@ -266,14 +274,20 @@ def init_sqlite():
|
||||
if col not in cols:
|
||||
conn.execute(f"ALTER TABLE missing_skus ADD COLUMN {col} {typedef}")
|
||||
logger.info(f"Migrated missing_skus: added column {col}")
|
||||
# Migrate sync_runs: add error_message column
|
||||
# Migrate sync_runs: add columns
|
||||
cursor = conn.execute("PRAGMA table_info(sync_runs)")
|
||||
sync_cols = {row[1] for row in cursor.fetchall()}
|
||||
if "error_message" not in sync_cols:
|
||||
conn.execute("ALTER TABLE sync_runs ADD COLUMN error_message TEXT")
|
||||
logger.info("Migrated sync_runs: added column error_message")
|
||||
if "already_imported" not in sync_cols:
|
||||
conn.execute("ALTER TABLE sync_runs ADD COLUMN already_imported INTEGER DEFAULT 0")
|
||||
logger.info("Migrated sync_runs: added column already_imported")
|
||||
if "new_imported" not in sync_cols:
|
||||
conn.execute("ALTER TABLE sync_runs ADD COLUMN new_imported INTEGER DEFAULT 0")
|
||||
logger.info("Migrated sync_runs: added column new_imported")
|
||||
|
||||
# Migrate orders: add shipping/billing/payment/delivery columns
|
||||
# Migrate orders: add shipping/billing/payment/delivery + invoice columns
|
||||
cursor = conn.execute("PRAGMA table_info(orders)")
|
||||
order_cols = {row[1] for row in cursor.fetchall()}
|
||||
for col, typedef in [
|
||||
@@ -281,6 +295,12 @@ def init_sqlite():
|
||||
("billing_name", "TEXT"),
|
||||
("payment_method", "TEXT"),
|
||||
("delivery_method", "TEXT"),
|
||||
("factura_serie", "TEXT"),
|
||||
("factura_numar", "TEXT"),
|
||||
("factura_total_fara_tva", "REAL"),
|
||||
("factura_total_tva", "REAL"),
|
||||
("factura_total_cu_tva", "REAL"),
|
||||
("invoice_checked_at", "TEXT"),
|
||||
]:
|
||||
if col not in order_cols:
|
||||
conn.execute(f"ALTER TABLE orders ADD COLUMN {col} {typedef}")
|
||||
|
||||
Reference in New Issue
Block a user