feat: invoices and bills take a project, line by line (B-37 item 8)

A client project's invoiced revenue and a contractor's billed cost could
never count toward the project: books.create_invoice and books.create_bill
posted at once with untagged lines, and only a draft's line takes a class.
Job costing (B-37 item 3) collects a job's billings and the supplier
invoices for its direct costs on its cost sheet, so each document line
now takes an optional project.

The owner decided it on 2026-10-22 (plan D-43, rules.md B-37 item 8):
each line takes one project or none; a document spanning N projects is N
lines, each with its own amount; no percentage split, so every figure is
exact; a cost truly shared among projects names none on the document
and reaches projects only as entries of their own under the company's
monthly allocation convention, when books.conventions has one (otherwise
it stays untagged and the agent asks the human). The reasoning, stated
in B-37: job costing charges a job the costs traceable to it, whole, and
reaches shared costs only by allocation on a stated basis. ASC
340-40-25-7 counts as directly related both the costs traceable to a
contract (25-7(a), (b), (d), (e)) and allocations of costs that relate
directly to it (25-7(c)); 25-8 expenses general and administrative cost.
The books carry the first whole on the document's line and the second as
the allocation convention's own entries; neither is a percentage on the
document (sources/fasb-asc.md, 25-7 and 25-8 added). The handbook's
projects rule and the line's class parameter say the same, and no
handbook sentence lets a shared cost be split across a document's lines.

The accounting: the document's entry posts one revenue (an invoice's) or
expense (a bill's) line per project its lines name, in the order each is
first named, each the sum of that project's lines, and the untagged
lines' sum as one more line (arap::document_parts, conservation checked
by a proptest). A document naming no project therefore posts exactly the
one line every document posted before. The receivable or payable line is
never tagged: it is a balance-sheet line, which item 3 counts nothing;
the payments (receive_payment, pay_bill) move cash against it and take no
project either. Nothing but the projects moves: the P&L, the 1099
worksheet (payments made, B-19) and party totals (what moved the money,
B-35) read the same with or without the tags (twin-books test); the
projects with the untagged lines still partition the P&L.

- ledger-core: DocumentLine.class_id (serde-omitted when none, so old
  documents serialize as before); create_invoice / create_bill split the
  revenue or expense side by project and tag it; an unknown project is
  refused whole (atomically).
- ledger-store: a document line's project is journaled as class_id on
  invoice.created / bill.created, and the entry's line as
  entry.line_class_set right after its entry.line_added (the entry.posted
  lines carry class_id, as a hand-built entry's do). Behind a NEW journal
  feature, document_line_projects (KNOWN_FEATURES, declared by new books,
  asked for before the first journaled line, not even the control
  accounts written on refusal); not `projects`, which the live books
  already declared: the owner consents again at the next upgrade. A
  malformed class_id is corrupt; null or absent is none. Untagged
  documents journal byte for byte as before; old journals replay
  unchanged.
- ledger-mcp: each line takes class (id or name, resolved like
  add_line's, every one before anything is written); the result gains
  notes for a finished or abandoned project, and on an invoice for an
  on-spec project (is there now an agreement? on spec a hoped-for
  payment is no receivable, B-37 item 4), tagged anyway; books lacking
  the feature refuse with format_upgrade_pending. books.get_entry shows a
  line's class_id and project. The handbook's "an invoice or bill takes no
  project yet" caveat now depends on the books: gone where the feature is
  declared, an "until their format upgrade" note where it isn't.
- ledger-gui: an invoice's or bill's page (its entry's) lists the
  document's lines, each project a link that opens it; the demo's client
  invoices are tagged to "Client work", whose snapshot is now its revenue
  less its contractors. Looking at the page in a narrow window found a
  tagged line's tag pushing the amounts past the pane (any tagged entry):
  the name is now cut to leave the tag room, the tag itself at most half
  the cell.
- bookspec: an `invoice` event, and `lines` with `project` on a bill or
  an invoice; example projects-invoice-and-bill-lines-count-by-project,
  worked by hand, both projects client work (Zeta 3,500.00 - 1,200.00 =
  2,300.00; Harbor 200.00;
  untagged -1,750.00; together the P&L's 750.00; Dana's 1099 payments
  1,250.00).
- fuzz: fuzz_store_replay can declare journal features.
- Tests: core, store, MCP, viewer, the P2-served cutover fixture and a
  viewer/server parity test (its month lists the same length, not
  empty); a tagged document's reversal nets its projects to zero, live
  and replayed; books.get_entry's class_id; the handbook served as a
  resource both ways; each fix broken to confirm its test fails
  (docs/testing.md). Docs: rules.md B-27 and B-37 items 3 and 8,
  sources/fasb-asc.md, plan/served.md D-43,
  mcp-interface.md, testing.md, parity.md, plan/STATUS.md.

No proof changed (no kernel arithmetic: document_parts sums with the
existing document_total).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-10-22 19:28:40 -06:00
1 parent e19df28bf2
commit 528c070605
51 files changed
+3201 -166

No files matched your search

+110
View File
@@ -2028,6 +2028,116 @@ fail.
rounding strategy; `project_figures`' opening net and running sum;
`profit_and_loss_counted`'s counts; `Standing::of`'s order.
## Invoices and bills take a project (2026-10-22)
rules.md B-37 item 8: each invoice and bill line takes an optional project
(`books.create_invoice` / `books.create_bill` `class`); the entry's revenue
or expense side is one line per project (`arap::document_parts`), the
receivable or payable and the payments untagged; journaled as the line's
`class_id` behind the new feature `document_line_projects` (B-27).
- **ledger-core:** `tests/spec_document_projects.rs`
(`an_invoices_revenue_is_one_line_per_project_and_the_receivable_none`,
`a_bills_cost_is_one_line_per_project_and_the_payable_none`,
`an_untagged_document_posts_as_before`,
`a_line_naming_an_unknown_project_is_refused_whole`,
`a_finished_project_still_takes_an_invoice`,
`tags_move_only_the_project_figures` (twin books, tagged and not: the
P&L, the 1099 worksheet and a party's activity identical; the projects
with the untagged lines partition the P&L),
`document_parts_refuse_past_exact_arithmetic`,
`reversing_a_tagged_document_takes_its_projects_to_zero` (a partial
payment moves no project figure; the reversal carries each line's
project, so every project nets to zero), and the proptest
`prop_document_parts_partition_the_total`); bookspec
`projects-invoice-and-bill-lines-count-by-project` (the loader gains an
`invoice` event and a document's `lines` with `project`; loader tests
`a_document_line_naming_an_unknown_project_is_refused`,
`a_document_with_an_amount_and_lines_is_refused`,
`an_invoice_lines_project_is_what_the_project_counts`).
- **ledger-store:** `tests/document_projects.rs`
(`a_tagged_invoice_journals_each_projects_line_and_replays`: the exact
lines, then verify, reopen and the viewer's snapshot;
`a_tagged_bill_tags_its_expense_lines_never_the_payable`;
`an_untagged_document_journals_as_before`: no `class_id` anywhere;
`a_document_naming_a_project_waits_for_the_feature`: books with
`projects` but not this feature refuse, journaling nothing, not even
the control accounts; `old_invoices_and_bills_replay_unchanged`: an
earlier version's journal opens, verifies, writes nothing;
`a_document_lines_class_id_that_isnt_an_id_is_corrupt`;
`a_reversed_tagged_invoice_replays_with_its_projects_at_zero`: one
`entry.reversed`, its replay tagged as live); `format.rs`
`document_line_projects_is_its_own_feature`.
- **ledger-mcp:** `tests/spec_projects.rs`
(`invoice_and_bill_lines_count_toward_their_projects`: by name, id and
any capitals; `books.get_entry`'s line `project` and `class_id`;
payments untagged;
`books.project`, `profit_and_loss_by_class`, `vendor_1099` and
`books.party` totals; `a_document_naming_an_unknown_project_is_refused_whole`,
`a_document_for_a_finished_project_says_so`,
`an_invoice_for_an_on_spec_project_asks_about_an_agreement` (an
invoice's note, a bill's none),
`books_without_the_feature_refuse_a_tagged_document` with the
handbook's text both ways, by `books.handbook` and as the
`books://handbook/projects` resource); `handbook.rs`
`document_projects_follow_the_books_feature` (no sentence lets a shared
cost be split on a document; the allocation convention only when
`books.conventions` has one).
- **ledger-gui:** `tests/projects.rs`
(`an_invoice_and_a_bill_show_each_lines_project`: each document line's
project a link that opens it, untagged lines bare;
`the_demos_client_work_counts_every_client_invoice`);
`pages::entry::tests::a_tagged_line_keeps_its_amounts_in_their_column`
(in a narrow pane a tagged line's name is cut to leave its tag room:
looking at the demo's invoice page at 1,100 points found the tag pushing
the credit column past the pane, a fault every tagged entry had);
`tests/screens.rs` shoots an invoice's and a bill's page.
- **ledger-cli:** `tests/projects_parity.rs`
(`invoiced_and_billed_project_figures_are_the_same_in_the_viewer_and_from_the_server`:
made through the server's tools, read by both, the month lists the same
length and not empty); `tests/format_upgrade.rs`
`books_p2_served_cut_over_whole` refuses a tagged invoice and bill
before consent and takes them after.
- **fuzz:** `fuzz_store_replay` can now declare features (this one
among them), so a document line's `class_id` reaches replay under a
declared format.
**Broken to confirm (each restored):** the core's revenue/expense line
left untagged (core 4 and store 3 tests fail); `document_parts` one part
per line (4 core, the proptest among them); the store's feature check
dropped (store gate test, MCP `books_without_the_feature_...`, CLI
`books_p2_served_cut_over_whole`); `document_line_json` without
`class_id` (3 store); `parse_document_lines` ignoring it (4 store, the
corrupt-id test among them); the `entry.line_class_set` not journaled (3
store, by verify); the MCP ignoring a line's `class` (4 MCP); no late-tag
notes (1 MCP); the handbook ungated (the handbook unit test and 1 MCP);
the handbook's rule without the owner's decision of D-43 (one project or
none a line, no percentage, a shared cost by the allocation convention:
the handbook unit test);
`books.get_entry` without `project` (2 MCP, the CLI parity test); the
viewer's document lines dropped, or their project not a link (the GUI
tests); no room kept back for the tag (the narrow-pane test); the demo's invoices untagged (the demo test); the bookspec loader
dropping a line's project (`every_bookspec_example_holds`). After
review: the projects handbook's old "split a shared cost across lines"
sentence restored, or the convention made unconditional (the handbook
unit test); no on-spec note, or one on a bill too (the on-spec MCP test);
the handbook resource served as if the feature were declared
(`books_without_the_feature_...`); `books.get_entry`'s `class_id`
dropped (`invoice_and_bill_lines_...`); the server's months cut short
(the parity test, which `zip` alone let pass); a reversal's line tags
dropped (the core and store reversal tests); the bookspec's Harbor made
on spec again (`every_bookspec_example_holds`). A separate
up-front unknown-class check in the core was removed: equivalent to
`set_line_class`'s own refusal inside `atomically`.
**For P12 (mutation targets):** `document_parts` (the first-appearance
order, the `contains` test); `add_document_parts`' tag index;
`ensure_document_lines`' `any`; `document_line_json`'s `if let`;
`parse_document_lines`' arms (null, absent, out of `u32`);
`document_notes`' dedup and its `invoice` flag; `on_spec_invoice_note`'s
kind test; `document_projects_rule`'s branch; the viewer's
`document_of` (invoice before bill).
## Benchmarks (baseline 2026-10-13)
No budget, by decision (the owner, 2026-10-13: the books do little work