fix(core): every reversal is dated on or after its original (D-73)

A correction comes after what it corrects (Pacioli ch. 31; B-9). Until now
only document reversals and depreciation/schedule runs were held to it; a
plain posted entry could be reversed with an earlier date, leaving the
books carrying the opposite of an entry that doesn't exist yet at the
reversal's date. The owner's decision D-73 (2026-11-08) makes it one rule
for every kind of entry; bookspec BS-ledger-5 states it.

- Ledger::check_reversal refuses date < original.date() with one error,
  ReversalBeforeOriginal (it replaces DocumentReversalBeforeOriginal,
  which was the document-only wording). Same-day reversals are allowed.
- Not on replay (B-28): the check sits behind is_replaying(), so a journal
  an earlier version wrote, holding a reversal dated before its original,
  reopens with the same figures.
- The store's own date check for depreciation runs and schedule months
  (InvalidSchedule / AssetEntryIrreversible wording) was the same rule
  for a narrower case; it is removed so there is one variant for all.
  Store::check_reverse_entry, books.reverse_entry (preview and post), and
  the document voids all reach the refusal through check_reversal; the
  only construction path for a reversal is reverse_entry_steps, which
  calls it first.

Tests: store reversal_dates.rs (plain entry refused before it, nothing
journaled, same day and later taken; a journal with an earlier-dated
reversal written the old way opens with the same figures); ledger-cli
spec_mcp (preview, unconfirmed and confirmed post all refuse alike).
Existing tests changed: store assets.rs (three expectations move to the
new variant); core spec_asset_basis.rs (it backdated a reversal on
purpose to check the trial balance carries -100.00 between the dates; it
now replays one, as an old journal would); model.rs (the model oracle's
`reverse` requires the date, as the Lean/bookspec rule does); bookspec
common.rs (the pinned depreciation example words this refusal
"entry_irreversible"); spec_documents.rs (variant rename).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-08 16:00:23 -07:00
1 parent c5fc16cad6
commit bb5008edb5
14 files changed
+278 -69

No files matched your search

+8 -5
View File
@@ -884,6 +884,7 @@ fn a_run_reinstated_after_its_rerun_was_reversed_still_counts() {
/// 1,535.71). So is a re-instatement dated before the reversal it reverses,
/// and a schedule month's reversal dated before its posting. A reversal on
/// the entry's own day is taken. Each refusal journals nothing.
/// Since D-73 the refusal is the ledger's for every entry, `ReversalBeforeOriginal`.
#[test]
fn a_reversal_dated_before_the_entry_it_reverses_is_refused() {
let (_dir, mut store) = open_store();
@@ -901,10 +902,12 @@ fn a_reversal_dated_before_the_entry_it_reverses_is_refused() {
for on in [date(2026, 2, 10), date(2026, 3, 30)] {
match store.reverse_entry(mar, on, "backdated") {
Err(ledger_store::StoreError::Ledger(
ledger_core::LedgerError::AssetEntryIrreversible(e, why),
ledger_core::LedgerError::ReversalBeforeOriginal {
entry, original, ..
},
)) => {
assert_eq!(e, mar);
assert!(why.contains("can't be dated before it"), "{why}");
assert_eq!(entry, mar);
assert_eq!(original, date(2026, 3, 31));
}
other => panic!("{on}: {other:?}"),
}
@@ -917,7 +920,7 @@ fn a_reversal_dated_before_the_entry_it_reverses_is_refused() {
assert!(matches!(
store.reverse_entry(rev, date(2026, 3, 30), "it was right"),
Err(ledger_store::StoreError::Ledger(
ledger_core::LedgerError::AssetEntryIrreversible(..)
ledger_core::LedgerError::ReversalBeforeOriginal { .. }
))
));
assert_eq!(store.head(), head);
@@ -951,7 +954,7 @@ fn a_reversal_dated_before_the_entry_it_reverses_is_refused() {
assert!(matches!(
store.reverse_entry(feb, date(2026, 1, 31), "backdated"),
Err(ledger_store::StoreError::Ledger(
ledger_core::LedgerError::InvalidSchedule(_)
ledger_core::LedgerError::ReversalBeforeOriginal { .. }
))
));
assert_eq!(store.head(), head);