Skip to content

feat(treasury): open-document sweep + auto commitment matching in Xero sync - #400

Open
adme-dev wants to merge 1 commit into
mainfrom
feat/treasury-sync-widen-automatch
Open

feat(treasury): open-document sweep + auto commitment matching in Xero sync#400
adme-dev wants to merge 1 commit into
mainfrom
feat/treasury-sync-widen-automatch

Conversation

@adme-dev

Copy link
Copy Markdown
Owner

Why

Parallel-run week 1 of the spreadsheet retirement (Monday board C-09/C-12) showed the invoice cache is windowed: the delta sync filters on modified time, so open bills entered before the cache was first warmed (floor ~20 Jul 2026) never land. Bossio's Dec-25 instalment bill and the WIN TV May-26 draft are in Xero but invisible to Treasury — which meant "absent from cache" could not be trusted to mean "absent from Xero", and forecast commitments could double-count real bills.

What

  • Open-document sweep in syncXeroInvoicesCache: after the delta pass, page AUTHORISED/SUBMITTED/DRAFT documents per type with no If-Modified-Since and no date floor. Open docs number in the dozens → ~1 extra API call per type per run, negligible under the post-fix: stop xero-customer-sync burning the 5,000/day Xero API quota #381 quota regime.
  • Auto commitment matching wired into fullCustomerSync: runs the existing commitmentMatcher (merged earlier) every sync cycle, applying auto-confidence matches only (contact/exact-name + amount ±1% + date ±30d). suggested matches still require a human via POST /api/cashflow/commitments/match. New commitmentsMatched field on XeroSyncResult.
  • Dedup guard inside the sync (upsertedIds) so delta + sweep never double-upsert.

Tests

  • New test/server/utils/xeroOpenDocsSweep.test.ts: sweep catches an open bill older than the delta window; sweep queries filter to open statuses without the delta header; no double-upsert across passes.
  • Full test/server/utils/ suite: 2,865 passed.

Context

Workstream W1 of .paul/PLAN-2026-08-13-spreadsheet-retirement-platform-work.md. W3 (treasury policy layer) and W2 (RepeatingInvoices push, gated on Kellie + accountant decisions, target 27 Aug) follow.

🤖 Generated with Claude Code

…o sync

The invoice sync's delta path windows on modified time, so open bills
entered before the cache was first warmed never landed (observed: cache
floor ~20 Jul 2026; Bossio Dec-25 and WIN TV May-26 bills invisible).
Treasury and the commitment matcher read this cache, so 'absent' had to
be verified in Xero by hand.

- Add an open-document sweep after the delta pass: pages AUTHORISED/
  SUBMITTED/DRAFT docs per type with no If-Modified-Since, no date floor.
  ~1 extra call per type per run; quota-neutral (PR #381 regime).
- Run the commitment matcher (auto tier only) inside fullCustomerSync so
  register estimates are superseded by real bills every sync cycle, not
  just when someone hits the manual match endpoint. Suggested-tier still
  requires human confirmation.
- commitmentsMatched added to XeroSyncResult.

Workstream W1 of .paul/PLAN-2026-08-13-spreadsheet-retirement-platform-work.md
(spreadsheet retirement, Monday board C-12).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant