Session 60 — Payments Ledger: UPRO-Account Invoices Re-Bucketed to Originating Branch

The problem

Dustin reported the /payments ledger at entirely.it.com showed “Unlikely Pro” as a branch, with Manassas invoices bucketed under it. Root cause: UP-assigned desk reviews (PPDR) and legacy triage projects intentionally sit on ACCOUNT_UNLIKELY_PRO for cert-routing reasons (see reference_ppdr_cert_routingis_ppdr_up_assigned is account-gated), but the payments endpoint derived branch from INVOICE_BRANCH_CODES[account_ss_id] FIRST, so those invoices surfaced as UPRO instead of their originating branch. 10 invoices affected: 9× MAN (T-MANA-INV-9166..9175, the 7/24 PPDR staging batch) + 1× BAL (T-BALT-INV-9140).

The fix (entirely-api 8b14f0a)

  • New _derive_invoice_branch() in routes/portal_payment_recon.py, replacing two duplicated inline copies (list endpoint + email-AP endpoint).
  • Precedence change: a UPRO account mapping is a weak signal — invoice-number prefix (after stripping T-), then triage_originating_branch, win over it. UPRO survives only for genuine direct-client invoices with no branch evidence.
  • Data untouched — the UPRO account assignment on PPDR projects is by design; only the ledger grouping was wrong.

Verification

Old vs new derivation diffed across all 1,503 invoiced rows: exactly the 10 misbucketed rows move (9→MANA, 1→BALT); the sole remaining UPRO row is UPR-9000 (216 Wildman St, genuine direct client). API rebuilt, worker/scheduler restarted, route smoke-tested.

Also this session

  • UPRO-INV-9148 (UPR-9000, Val Wood, 216 Wildman St NE Leesburg, $1,200) marked Paid per Dustin — manual payment recorded with payment_date 2026-07-21 via /revolut/payment/manual + /revolut/payment/sync-status; Supabase invoice_status verified Paid.
  • Latent bug spotted: payment_reconciliation.update_smartsuite_payment_status divides invoice_total by 100 (cents assumption) — read 12. Harmless here (paid ≥ real total) but would wrongly mark partial payments as Paid.

Related: payment reconciliation, portal_payment_recon, reference_ppdr_cert_routing