merge: P4b S7, bad debts (branch S7, 4b4fecb9)

The fourth of the paused branches: Ledger::write_off and the bad_debts
control role, invoice.written_off with its evidence filed in the same
store call, books.write_off_invoice, the write-off on the timeline and
in Needs attention, Lean writeOff_within_bounds, rules.md B-41 and the
bookspec examples. Twenty-eight files conflicted with the S4.4, S5 and
S6 merges; resolved as plan 8.0.2 says, keeping both sides' appends with
their seams restored, and: the scope table at 125; S7's law numbered 37;
B-41 placed before B-42; the handbook's step 4 and recovery procedures
folded into the one invoices-and-bills section; S7's wire tests in their
own module with the confirm S4.4's contract needs; S7's copy of the
payment steps dropped (S6 replaced them with Ledger::settle) and its
write-off journaled through S6's journal_auto_lines; in the old-books
fixture S7's hand-written write-off moved to a second invoice, since
S6's hand-written payment settles invoice 1 in full.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
swaitsandClaude Fable 5.1 committed 2026-10-28 21:47:33 -06:00
commit 335a3eaa7e
47 files changed
+2883 -74

No files matched your search

@@ -64,6 +64,60 @@ without another copy to correct (B-38).
Discounts / Cr the asset account (D-49). Never split the discount across
the asset lines.
## 4. Void, write off, or reverse
One of these, and only one, fits what happened:
- **Void it** (`books.void_document`) when the document should never have
existed: a duplicate, the wrong customer or vendor, a test entry. It is
reversed, keeps its id (and, once numbered, its number) and reads void;
nothing is deleted. Refused while a payment stands on it: reverse that
payment first, and the refusal names it. Use a void for a mistake, never
for an invoice that was real.
- **Write it off** (`books.write_off_invoice`) when the invoice was real
and the work or goods went out, but the customer will not or cannot pay.
That is a bad debt: the books post Dr Bad Debt Expense 6990 / Cr Accounts
Receivable for what will not be collected, and what it owes falls from
that day. The evidence of worthlessness — the collection letters, the
bankruptcy or liquidation notice, the collection agency's report — is
filed with the write-off in the same call (`upload_id`, or an
`existing_attachment_id` already filed), because a bad debt is deducted
on all the pertinent evidence (Treas. Reg. §1.166-2(a)). Write off all of
it, or part of it with `amount`: a partial write-off is deductible to the
extent charged off (Treas. Reg. §1.166-3(a)), and the rest stays owed and
in the aging. The books must be on the accrual basis: a cash-basis
company never counted the invoice as income, so there is no basis to
deduct (IRC §166; Treas. Reg. §1.166-1(e)), and the tool refuses.
- **Reverse an entry** (`books.reverse_entry`) when a posted entry is
wrong: a payment against the wrong invoice, a wrong amount, a check that
bounced, a write-off made too soon. Posted is forever: the correction is
an opposite entry linked to the one it reverses, never an edit and never
a delete. Reversing a payment puts the invoice back to owing what it did;
reversing a write-off re-instates the debt.
A bill is never written off: a vendor releases you with a vendor credit or
by voiding its own invoice, and until then you owe it (ASC 405-20-40-1). If
a vendor's bill was wrong, ask for a corrected bill or record a credit when
one is built; void it only when it should never have been entered.
## Recovering a debt written off
- **The same tax year**: reverse the write-off — `books.reverse_entry` on
the write-off's entry. The invoice reopens, owing exactly what the
write-off took off; then record the payment with `books.receive_payment`
as usual. Nothing else is needed: within the year the deduction comes
back out, and the payment is a payment.
- **A later tax year**: do not reverse the write-off. Record a plain entry
— `books.draft_entry`, `books.add_line` on each side, `books.post_entry`
— debiting the deposit account and crediting a "Bad debt recoveries"
revenue account (tax category other income), with a memo naming the
invoice. The invoice stays written off, and the recovery is income in the
year it arrives (IRC §111); the CPA sees it apart from the year's sales.
Neither procedure invents a new kind of movement on the document: the books
record what happened, and the invoice's timeline shows the write-off (and,
if it was reversed, that it no longer stands).
## 5. A processor's fee
- The books never charge or collect; a processor does, and keeps a fee.
@@ -83,3 +137,21 @@ without another copy to correct (B-38).
3. Apply the parked money with `books.receive_payment`,
`deposit_to: "2300"`, dated on or after the bounce, against the
invoices it pays. The 2300 balance returns to zero.
## What the CPA will check
The agings tie to 1200 and 2000 at month and year end (they do by
construction: the control check says so). Every write-off carries its
reason and its evidence of collection efforts. Write-offs are not used in
place of a credit memo for a valid invoice, and never to hide a mistake
that a void would show. Whether a debt is worthless, and in which year, is
a tax judgment that stays with the CPA: the books flag each write-off made
this year in Needs attention, with the evidence beside it, until the year
ends.
## The evidence rule
Every entry needs its receipt ({evidence_rule}). A document the books post
themselves — an invoice, a bill, a payment, a write-off — carries its own:
the issued copy, the vendor's bill, the payment's reference, the evidence of
worthlessness. A reversal needs none of its own: its original carries it.