feat(evidence): one function decides whether an entry needs evidence (P4)

Accounting reason: the receipt rule (Pub. 583, Rev. Proc. 98-25: the
books must be demonstrably supported by the records) was decided in
three places that could disagree: the server's post, the digest, and a
string match on a journal-event origin in the viewer. ledger_core::
evidence::requirement is now the one decision: Required (with why) or
Exempt (with the source). A reversal needs no receipt of its own (its
evidence is its original's, D-47, D-12); neither do a closing entry, a
schedule month's or a depreciation run's posting, a disposal, a
document's entry, a payroll run or its remittance. The ledger learned
the two origins it could not see (a disposal, a remittance) from the
events that already name their entry, live and on replay. A split group
counts for a draft only: a posted entry's decision was made when it
posted.

The policy moved with it (evidence::Policy; ReceiptPolicy in
ledger-config keeps the words and delegates). Store::post_entry_checked
refuses a covered draft with no receipt (StoreError::ReceiptRequired,
which the MCP maps to the unchanged receipt_required error);
Store::post_entry stays the primitive that commands and fixtures post
through, since ~176 call sites post hand entries with no receipt. The
viewer's missing_receipt calls requirement; its string match is gone.

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-29 13:55:17 -06:00
1 parent 28d46332e4
commit 7299cf90f2
6 files changed
+451 -132

No files matched your search

+57
View File
@@ -355,6 +355,10 @@ pub struct Ledger {
/// What each entry settles (`entry.settles`, plan P6): the one record
/// a member-paid entry's "reimbursed" is derived from (IZ-18).
entry_settles: std::collections::BTreeMap<EntryId, Vec<EntryId>>,
/// What posted the entries the ledger's other state doesn't say
/// ([`crate::evidence::Origin`]): an asset's disposal, a payroll tax
/// remittance. Read by [`crate::evidence::requirement`].
entry_origins: std::collections::BTreeMap<EntryId, crate::evidence::Origin>,
/// The journal line that posted each posted entry (`entry.posted` or
/// `entry.reversed`, plan P4): what "posted since seq N" is read from,
/// backdated entries included. An entry the journal's own posting
@@ -424,6 +428,7 @@ impl Ledger {
conventions: crate::conventions::Conventions::default(),
annotations: std::collections::BTreeMap::new(),
entry_settles: std::collections::BTreeMap::new(),
entry_origins: std::collections::BTreeMap::new(),
posted_seq: std::collections::BTreeMap::new(),
expected_seq: std::collections::BTreeMap::new(),
unstamped: Vec::new(),
@@ -843,6 +848,7 @@ impl Ledger {
("annotations", self.annotations == other.annotations),
("entry_settles", self.entry_settles == other.entry_settles),
("posted_seq", self.posted_seq == other.posted_seq),
("entry_origins", self.entry_origins == other.entry_origins),
]
.into_iter()
.filter(|(_, same)| !same)
@@ -2102,6 +2108,57 @@ impl Ledger {
self.posted_seq.get(&entry).copied()
}
/// Record what posted `entry` where the ledger's other state doesn't
/// say: an asset's disposal entry, a payroll tax remittance (the store,
/// live, after the command; on replay, from the event that names the
/// entry). Read by [`crate::evidence::requirement`].
#[doc(hidden)]
pub fn note_entry_origin(&mut self, entry: EntryId, origin: crate::evidence::Origin) {
self.entry_origins.insert(entry, origin);
}
/// Why `entry` needs no evidence of its own, by what posted it, if
/// that is so ([`crate::evidence::requirement`] INVARIANT 1); `None`
/// for an entry the receipt policy covers (a hand entry, a recurring
/// draft, a payout).
pub(crate) fn origin_exemption(&self, entry: &JournalEntry) -> Option<&'static str> {
let id = entry.id();
if entry.reversal_of().is_some() {
return Some("a reversal: its evidence is its original's (B-43, D-47, D-12)");
}
if self.is_closing_entry(id) {
return Some("a period's closing entry: derived from the books (B-43)");
}
if self.schedule_month_of(id).is_some() {
return Some("a schedule month's posting: the schedule is the evidence (B-43)");
}
if self
.asset_runs
.values()
.any(|runs| runs.iter().any(|r| r.entry == id))
{
return Some("a depreciation run: the asset's schedule is the evidence (B-43)");
}
match self.entry_origins.get(&id) {
Some(crate::evidence::Origin::AssetDisposal) => {
return Some("an asset's disposal: the register is the evidence (B-43)");
}
Some(crate::evidence::Origin::PayrollRemittance) => {
return Some("a payroll tax remittance: the payroll runs are the evidence (B-43)");
}
None => {}
}
if (0..entry.lines().len()).any(|i| self.line_docs.contains_key(&(id, i))) {
return Some(
"a document's entry (invoice, bill, payment, write-off): the document is the evidence (B-43)",
);
}
if self.payroll_runs.values().any(|r| r.entry_id == id) {
return Some("a payroll run: the run is the evidence (B-43)");
}
None
}
/// Say that journal line `seq` will be `entry`'s posting line, ahead
/// of the command that posts it (a store, live: it journals
/// `entry.posted` or `entry.reversed` first). Consumed when the entry