feat: Add AR/AP duality support with event handlers and ledger reads#676
Conversation
- Added BILL_PAID_HANDLER and PAYMENT_RECEIVED_HANDLER to the event block registry for handling bill payments and received payments respectively. - Implemented linked transaction parsing in OLTPLoader to capture invoice/bill references from payments. - Introduced new AR/AP read operations to compute open balances and list receivables/payables by agent. - Developed tests for the new bill_paid and payment_received handlers, ensuring correct linkage and dispatch behavior. - Added smoke tests for AR/AP read operations to validate SQL compilation and response shapes.
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 2m 41s —— View job PR Review: feat: Add AR/AP duality support with event handlers and ledger readsTasks
Overall AssessmentThis is a well-designed, well-documented PR. The AR/AP duality approach — using an event-graph model where Issues to Address1. Behavior Change in Rules Engine is Bundled in this PR
2. Discharge Target Candidates Not Filtered by StatusIn For most QB syncs this is benign (QB syncs are sequential so invoices precede payments in the event store). But during a fresh full re-sync where auto-commit runs in external_id order, a payment may be processed before its invoice has been committed. The discharge link would be set to a # In _resolve_by_linked_txns — consider adding:
Event.status.in_(("committed", "fulfilled")),3. NULL
|
…payment resolution
…ed transaction tracking
Summary
Introduces Accounts Receivable / Accounts Payable (AR/AP) duality handling across the platform, spanning data modeling, event processing, GraphQL APIs, and ledger read operations. This feature enables the system to properly track and reconcile the dual nature of AR/AP transactions — where a receivable or payable on one side corresponds to a payment or bill settlement on the other.
Key Accomplishments
Data Layer (dbt Models)
transactions.sqlledger model to account for AR/AP duality in transaction aggregationbill_headers,bill_payment_headers,invoice_headers,payment_headers,purchase_headers,sales_receipt_headers) to surface fields needed for AR/AP trackingAPI Models & GraphQL
ar_ap.pyAPI extension model defining the data structures for AR/AP dualityEvent Handlers
bill_paidhandler — processes bill payment events, linking AP settlements to their originating billspayment_receivedhandler — processes incoming payment events, linking AR settlements to their originating invoices; includes comprehensive logic (~250 lines) for matching and reconciliationLedger Read Operations
ar_ap.pyread module (~208 lines) providing query operations for AR/AP balances, aging, and duality lookupsPipeline Utilities
Extensions Loader
Rules Engine
Breaking Changes
None expected. All changes are additive — new handlers, new models, new read operations, and new GraphQL types/resolvers. Existing staging models received additional columns but no removals or renames.
Testing
test_bill_paid.py— 76 lines covering bill payment event handler scenariostest_payment_received.py— 283 lines with comprehensive coverage of payment received logic including edge cases and reconciliation matchingtest_ar_ap.py(reads) — 112 lines testing AR/AP ledger read operationstest_utils.py— expanded with 118 additional lines for new pipeline utility functionstest_registry.py— updated to validate registration of the two new event handlersTotal new/modified test coverage: ~600+ lines across 5 test files.
Infrastructure Considerations
dbt runon the affected staging and ledger models to materialize the new columns in the data warehouse🤖 Generated with Claude Code
Branch Info:
feature/ar-ap-dualitymainCo-Authored-By: Claude noreply@anthropic.com