Root cause of the 2GB prod import.db: the sync_run_orders audit junction
recorded every order on every run; under the 1-minute scheduler ~98% of
21.7M rows were no-op ALREADY_IMPORTED re-observations. NSSM stdout/stderr
also grew unbounded (rotation never applied to the live service).
Changes:
- sqlite_service: skip ALREADY_IMPORTED rows in sync_run_orders (write-side
guard, _SKIP_JUNCTION_STATUSES); add prune_sync_history(retention_days)
with incremental_vacuum.
- maintenance_service (new): cleanup_old_logs + run_daily_maintenance.
- scheduler_service: start_maintenance_job (daily CronTrigger).
- main.py: RotatingFileHandler (sync_comenzi_current.log, 10MB x5) instead
of a new timestamped file per start; schedule daily maintenance + one-shot
catch-up at startup.
- scripts/db_maintenance.py (new): one-shot prune + VACUUM + log cleanup,
plain sqlite3, invoked by deploy.ps1 while the service is stopped.
- deploy.ps1: stop -> run db_maintenance.py -> (re)apply NSSM AppRotate*
idempotently -> start, so rotation reaches pre-existing services.
Retention defaults: 7 days history, 7 days logs.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Linking the VANZARI header (ID_COMANDA) makes the app dashboard show an
order facturat, but ROA decides facturat at the LINE level
(PACK_FACTURARE.cursor_comanda matches invoiced qty on ID_ARTICOL + exact
PRET). When a manual invoice represented lines differently than the order
(e.g. per-VAT-rate discounts consolidated into one 0%-TVA line), the order
stays nefacturat in ROA despite the header link.
Add order_line_residual(): predicts the residual before --apply (via
extra_idv) and re-verifies after linking. Warns in the plan, the summary
counter, and post-apply when an order will still show nefacturat. The
script never touches COMENZI_ELEMENTE — those need a manual line fix.
Surfaced by orders 5419/5423 (web 492710430/492710513) on 2026-06-26.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sets the Oracle thick-mode env (TNS_ADMIN + instant client PATH) like start.bat,
resolves venv/script paths relative to itself, forwards all args, and pauses so
output is readable. Run on the VENDING prod server (double-click = dry-run).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tool to relink orphan VANZARI invoices (ID_COMANDA NULL, sters=0) — emitted
manually by the warehouse during an Oracle/sync outage — to their GoMag order,
then populate the SQLite invoice cache like the app does.
Matching is conservative (exact total + partner OR name; handles duplicate
partner records) and only auto-links unambiguous 1:1 matches. Genuine warehouse/
walk-in invoices (no online order behind them) get SKIP_NOMATCH and are left
untouched; anything unclear is reported SKIP_AMBIGUOUS for manual review.
Dry-run by default; --apply / --yes / --days N. Runs on prod (uses app.config
settings + prod import.db). Codifies the 2026-06-26 manual relink (12 invoices).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Script failed with "SQLite not initialized" because module-level connection
state wasn't set up when invoked standalone.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two production bugs from VENDING (order 485224762, 2026-04-22):
1. Oracle: ORA-20000 when a GoMag order contains a kit SKU whose expansion
includes CODMAT X plus a second item with SKU=X. Two article-insert
call-sites in PACK_IMPORT_COMENZI bypassed merge_or_insert_articol —
line 622 (NOM_ARTICOLE fallback) and line 538 (kit discount line).
Both now use merge_or_insert_articol for consistent dedup semantics.
Regression test added in test_complete_import.py covering the exact
kit-plus-direct scenario.
2. SQLite: retry_service._download_and_reimport refreshed orders row but
never repopulated order_items. Combined with mark_order_deleted_in_roa
(which wipes items), any retry/resync left the UI showing "Niciun
articol" despite successful Oracle import. Retry now rebuilds items
from the fresh GoMag download on both success and error paths,
mirroring sync_service.
Includes scripts/backfill_order_items.py — one-shot recovery for orders
already in this bad state. Reads settings, re-fetches from GoMag,
rewrites order_items without touching Oracle or order status.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Customers often swap firstname/lastname in GoMag forms, causing duplicate
partner creation in Oracle. Fix with two layers:
- Python: sort PF name words alphabetically before Oracle lookup
- PL/SQL: add Step 2b permutation search (2-3 word names, PF only)
- Normalize name order to lastname+firstname across all Python files
- Add diagnostic SQL for finding existing reversed-name duplicates
- Add Oracle integration test for reverse-name matching
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevent partner duplicates via ANAF CUI verification and dual PL/SQL
search. Fix address matching with street-level comparison and diacritics
normalization. Show partner/address comparison in order detail modal.
- New anaf_service.py: batch ANAF API client with chunking, retry, cache
- PL/SQL: dual CUI search (bare/RO+bare/RO space+bare), 3-tier address
search (street+city+id_loc → city+id_loc → create), strip_diacritics
at storage for addresses and partner names
- SQLite: anaf_cache table, 12 new order columns for partner/address data
- import_service: cod_fiscal_override param, return partner/address from Oracle
- sync_service: ANAF batch integration, denomination mismatch detection,
cache pre-population trigger
- Router: enriched order_detail with partner_info + addresses JSON
- UI: collapsible Detalii Partener + Adrese Comparativ sections in modal,
auto-expand on mismatch, ANAF badges, mobile address cards
- Dashboard: address quality attention indicator
- New scan_duplicate_partners.py script for one-time duplicate audit
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Delete README-ORACLE-MODES.md (references Docker infra that doesn't exist)
- Delete .claude/HANDOFF.md (completed CI/CD session handoff, no longer needed)
- Fix api/README.md: correct run command to ./start.sh, update test commands
to use ./test.sh instead of deleted test_app_basic.py/test_integration.py
- Fix scripts/HANDOFF_MAPPING.md: mark deleted scripts as removed
- Remove dead README-ORACLE-MODES.md link from README doc table
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 decimal places in STOC.PRET caused FACT-008 errors during invoicing
because pack_facturare.descarca_gestiune does exact price matching.
Also add pack_facturare flow analysis documentation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Script syncs articles from VENDING (prod) to MARIUSM_AUTO (dev)
via SSH. Supports dry-run, --apply, and --yes modes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevents untracked file conflicts on git pull on Windows server.
Scripts are development/analysis tools, not part of the deployed app.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Documents what was tried, what worked (order-invoice matching),
what failed (line item matching by price), and proposed strategy
for next session (subset → confirm → generalize).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>