feat(sqlite): refactor orders schema + dashboard period filter
Replace import_orders (insert-per-run) with orders table (one row per order, upsert on conflict). Eliminates dedup CTE on every dashboard query and prevents unbounded row growth at 4-500 orders/sync. Key changes: - orders table: PK order_number, upsert via ON CONFLICT DO UPDATE; COALESCE preserves id_comanda once set; times_skipped auto-increments - sync_run_orders: lightweight junction (sync_run_id, order_number) replaces sync_run_id column on orders - order_items: PK changed to (order_number, sku), INSERT OR IGNORE - Auto-migration in init_sqlite(): import_orders → orders on first boot, old table renamed to import_orders_bak - /api/dashboard/orders: period_days param (3/7/30/0=all, default 7) - Dashboard: period selector buttons in orders card header - start.sh: stop existing process on port 5003 before restart; remove --reload (broken on WSL2 /mnt/e/) - Add invoice_service, E2E Playwright tests, Oracle package updates Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -88,9 +88,9 @@ async def scan_and_validate():
|
||||
async def get_missing_skus(
|
||||
page: int = Query(1, ge=1),
|
||||
per_page: int = Query(20, ge=1, le=100),
|
||||
resolved: int = Query(0, ge=0, le=1)
|
||||
resolved: int = Query(0, ge=-1, le=1)
|
||||
):
|
||||
"""Get paginated missing SKUs."""
|
||||
"""Get paginated missing SKUs. resolved=-1 means show all (R10)."""
|
||||
result = await sqlite_service.get_missing_skus_paginated(page, per_page, resolved)
|
||||
# Backward compat: also include 'unresolved' count
|
||||
db = await get_sqlite()
|
||||
@@ -106,7 +106,7 @@ async def get_missing_skus(
|
||||
|
||||
@router.get("/missing-skus-csv")
|
||||
async def export_missing_skus_csv():
|
||||
"""Export missing SKUs as CSV."""
|
||||
"""Export missing SKUs as CSV compatible with mapping import (R8)."""
|
||||
db = await get_sqlite()
|
||||
try:
|
||||
cursor = await db.execute("""
|
||||
@@ -120,9 +120,9 @@ async def export_missing_skus_csv():
|
||||
|
||||
output = io.StringIO()
|
||||
writer = csv.writer(output)
|
||||
writer.writerow(["sku", "product_name", "first_seen"])
|
||||
writer.writerow(["sku", "codmat", "cantitate_roa", "procent_pret", "product_name"])
|
||||
for row in rows:
|
||||
writer.writerow([row["sku"], row["product_name"], row["first_seen"]])
|
||||
writer.writerow([row["sku"], "", "", "", row["product_name"] or ""])
|
||||
|
||||
return StreamingResponse(
|
||||
io.BytesIO(output.getvalue().encode("utf-8-sig")),
|
||||
|
||||
Reference in New Issue
Block a user