← All manuals IM2

Workbench live on-hand and on-PO — technical specification

PO Workbench
Technical Spec Ver 1 Updated 2026-09-07 Matches the live screen

Live OH / On PO (app/live_qty.py)

Dave, 2026-09-06: the workbench must show on-hand and on-PO as at the moment it is run, not last night's sync.

What runs on every workbench load

  1. On handselect Id, QtyOnHand from Item where Type='Inventory', the whole catalogue (1,480 items), written into items.qty_on_hand in one execute_values statement. ~1.1s.
  2. On PO — QuickBooks Change Data Capture (GET /v3/company/{realm}/cdc, entities=PurchaseOrder&changedSince=<cursor>), applied to qb_po_line delete-then-insert per PO. ~0.5s. Cursor lives in qb_cdc_cursor.

Total ~1.7s and flat in the number of ROs — scoping the item pull to the SKUs on ROs was tried first and abandoned: hundreds of RO SKUs are coming once service tickets load, and the whole catalogue costs the same.

Things that will bite whoever changes this

The nightly 02:45 sync_qb_open_pos.py still runs and is still the safety net.

Ver 2 - 2026-09-07 - refresh throttle

live_qty.refresh(ro_conn, im2_conn, force=False) re-uses the previous snapshot when it is younger than MIN_AGE_SECS (120) and returns reused=True with the original timestamp, so the stamp never claims a pull that did not happen. State lives in table qb_live_refresh (single row, created on first use). force=True always pulls.

The workbench being slow was not QuickBooks. company_holidays() was called once per row and each call with no connection to hand opened its own database connection to read Settings - 102 rows cost 4.3s of a 5s page. Names and resolved holiday dates are now cached in po.py for 60s (_HOLIDAY_CACHE). The page went from ~7.4s to ~0.4s; the live QuickBooks pull is ~1.9s and only on a cold snapshot.

Ver 2 — 2026-09-07 — refresh throttle

re-uses the previous snapshot when it is younger than (120) and returns with the original timestamp, so the stamp never claims a pull that did not happen. State lives in (single row, created on first use). always pulls.

The workbench being slow was not QuickBooks. was called once per row and each call opened its own database connection to read Settings — 102 rows cost 4.3s of the 5s page. Names and resolved holiday dates are now cached in for 60s (). Page went from ~7.4s to ~0.4s; the live pull itself is ~1.9s and only on a cold snapshot.