Skip to content

Phase 2.5: Cross-reference rules (E002, E003, E007, E010, E014) - #12

Merged
withrvr merged 5 commits into
claude/erp-collection-reporting-workflow-iycqtofrom
phase/02-05-cross-reference-rules
Aug 31, 2026
Merged

withrvr merged 5 commits into
claude/erp-collection-reporting-workflow-iycqtofrom
phase/02-05-cross-reference-rules

Conversation

@withrvr

@withrvr withrvr commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Phase 2 (feature 5 of 6): Cross-reference rules

What this adds

The five rules spanning two sheets: E002 (unknown customer reference, on
either invoices or payments), E003 (unknown invoice reference), E007
(payment-to-invoice customer mismatch — the flagship worked example from
MASTER_PLAN.md section 8 and QA_PREP.md Q11)
, E010 (payment before
invoice date, flag-only per README's documented assumption), and E014
(overpayment — beyond the assessment's required list, added because the
data called for it, QA_PREP.md Q5).

All 14 rules are now implemented and registered. Verified against dataset
A: 17 exception rows across all 14 codes, exactly matching RULES.md's
summary table.

Assessment requirement served

Covers the remaining required categories: "unknown customers/invoices,"
"customer mismatch," and "payment before invoice" — plus E014, added
beyond the brief.

Docs updated

  • README.md (Phase 2's "Validation performed" section lands in PR6)
  • ARCHITECTURE.md
  • API.md
  • RULES.md — all 14 entries now written, status line updated to
    "14/14 rules implemented"
  • DEVELOPMENT.md
  • CHANGELOG.md (Phase 2's entry lands in PR6)

Verification

cd backend && uv run pytest app/collections/tests -v
# 100 passed

uv run python -m app.collections.scripts.reference_summary
# still 15 overdue / Rs 1,202,000.00 / West heaviest -- Phase 2 explains
# exclusions, doesn't change Phase 1's numbers

# manual cross-check: every rule fires, 17 rows total, matches RULES.md
python -c "... exceptions_by_rule(...) ..." # E001-E014 all present, sums to 17

Known gaps carried to next phase

  • test_coverage.py and test_reconcile.py (invoice-amount and
    payment-centric identities) land in PR6, along with the final
    RULES.md/README.md/CHANGELOG.md consistency pass and the
    v0.3.0 tag attempt.

Generated by Claude Code

claude added 5 commits August 31, 2026 11:41
Checked against both invoices and payments, since either kind of
record can carry a dangling Customer_ID. Fires independently of E003
when both a payment's customer and invoice reference are unknown
(PAY-2025) -- two true, independently actionable facts, not one
combined flag. Fires on INV-1026 and PAY-2025 (both C999) in
dataset A.

Refs: docs/RULES.md
A payment referencing an invoice that doesn't exist in the Invoices
sheet is never applied to anything, since outstanding.py's payment
index is keyed by real invoice IDs. Fires on PAY-2025 (Invoice_ID
INV-9999) in dataset A -- the same row that independently fires E002
for its unknown customer reference.

Refs: docs/RULES.md
Payments can reference an invoice belonging to a different customer.
PAY-2026 pays INV-1002 under C003 while the invoice belongs to C002.
The payment is excluded from the paid total and flagged rather than
reassigned, since reassignment would be a silent data correction.

Refs: docs/RULES.md
Flags a payment dated before its own invoice's invoice date as a
data-quality item, without excluding it from compute_outstanding --
the workbook doesn't authorize that exclusion, only this rule's
documented assumption does (see README.md). Fires on PAY-2027 against
INV-1004 in dataset A.

Refs: docs/RULES.md
Not on the assessment's required list -- added because the data
called for it (QA_PREP.md Q5). Reuses outstanding.py's own
valid_payments_total so this rule can never disagree with the real
calculation about what counts as a valid payment, and floors nothing
itself since compute_outstanding already floors at zero -- this rule
only explains why. Fires on INV-1007 (88,000 invoiced, 110,000 paid,
22,000 overpaid) in dataset A.

All 14 rules now implemented and registered; RULES.md's catalogue is
complete and matches the code.

Refs: docs/RULES.md
@withrvr
withrvr merged commit f67216e into claude/erp-collection-reporting-workflow-iycqto Aug 31, 2026
4 of 7 checks passed
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.

2 participants