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:
1 parent
c5fc16cad6
commit
bb5008edb5
14 files changed
+278
-69
No files matched your search
@@ -1983,6 +1983,47 @@ fn inv4_post_and_reverse_preview_without_confirmed() {
|
||||
assert_eq!(tb["balanced"], true);
|
||||
}
|
||||
|
||||
/// D-73: a reversal is dated on or after its original, for every entry. The
|
||||
/// preview refuses as the post does, naming the dates, and neither journals
|
||||
/// anything; the same day is taken.
|
||||
#[test]
|
||||
fn a_reversal_dated_before_its_entry_is_refused_in_preview_and_post() {
|
||||
let dir = test_dir("rev-dated-before");
|
||||
let toml = books_toml(&dir, "0.00", "");
|
||||
let mut m = Mcp::start(&dir, &toml);
|
||||
m.accounts(BASE_CHART);
|
||||
let e = m.draft(
|
||||
"2026-05-10",
|
||||
"Rent",
|
||||
&[("6000", "debit", "500.00"), ("1000", "credit", "500.00")],
|
||||
);
|
||||
m.attach(Some(e), b"rent receipt");
|
||||
m.post(e).ok("post");
|
||||
let before = m.journal();
|
||||
for confirmed in [None, Some(false), Some(true)] {
|
||||
let mut args = json!({"entry_id": e, "date": "2026-05-09", "description": "early"});
|
||||
if let Some(c) = confirmed {
|
||||
args["confirmed"] = json!(c);
|
||||
}
|
||||
let why = m.refuse("books.reverse_entry", args);
|
||||
assert!(
|
||||
why.contains("can't be dated before it") && why.contains("2026-05-10"),
|
||||
"{why}"
|
||||
);
|
||||
}
|
||||
assert!(m.journal() == before, "a refused reversal wrote");
|
||||
let p = m.ok(
|
||||
"books.reverse_entry",
|
||||
json!({"entry_id": e, "date": "2026-05-10", "description": "same day"}),
|
||||
);
|
||||
assert_eq!(p["status"], "preview", "{p}");
|
||||
m.ok(
|
||||
"books.reverse_entry",
|
||||
json!({"entry_id": e, "date": "2026-05-10", "description": "same day",
|
||||
"confirmed": true}),
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------ invariant 5: receipt policy
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -833,17 +833,13 @@ pub enum LedgerError {
|
||||
#[error("{0}")]
|
||||
DocumentBounds(String),
|
||||
|
||||
/// A reversal of an entry an invoice or bill owns is dated before that
|
||||
/// entry (rules.md B-9, B-38): a correction comes after what it
|
||||
/// corrects.
|
||||
#[error(
|
||||
"entry {entry} belongs to {document} and is dated {original}: its reversal can't be dated before it, on {date}"
|
||||
)]
|
||||
DocumentReversalBeforeOriginal {
|
||||
/// A reversal is dated before the entry it reverses (rules.md B-9,
|
||||
/// D-73): a correction comes after what it corrects, for every kind of
|
||||
/// entry. New commands only; replay never refuses (B-28).
|
||||
#[error("entry {entry} is dated {original}: its reversal can't be dated before it, on {date}")]
|
||||
ReversalBeforeOriginal {
|
||||
/// The entry reversed.
|
||||
entry: u64,
|
||||
/// The document, e.g. "invoice 7".
|
||||
document: String,
|
||||
/// The entry's date.
|
||||
original: chrono::NaiveDate,
|
||||
/// The reversal's date.
|
||||
|
||||
@@ -2235,12 +2235,15 @@ impl Ledger {
|
||||
/// - NEVER recognize one month of a schedule twice
|
||||
/// BECAUSE a reversed month is due again and may have been run
|
||||
/// again (P3 depreciation review R3).
|
||||
/// 6. IF the entry carries a document's lines (an invoice's or a
|
||||
/// bill's own entry, a payment, or a reversal of one) and `date`
|
||||
/// is before the entry's own date:
|
||||
/// - SHOULD refuse (DocumentReversalBeforeOriginal)
|
||||
/// BECAUSE a correction comes after what it corrects (B-9; plan
|
||||
/// P4b.3, "Dating rules").
|
||||
/// 6. IF `date` is before the entry's own date (any kind of entry:
|
||||
/// plain, document, payment, schedule run):
|
||||
/// - SHOULD refuse (ReversalBeforeOriginal)
|
||||
/// - NEVER refuse the same day
|
||||
/// - NEVER refuse on replay
|
||||
/// BECAUSE a correction comes after what it corrects (B-9; owner
|
||||
/// decision D-73, 2026-11-08; plan P4b.3, "Dating rules"). Books
|
||||
/// written before D-73 may hold an earlier-dated reversal and
|
||||
/// reopen as they were (B-28).
|
||||
/// 7. IF reversing it would leave a document it carries owing less
|
||||
/// than nothing or more than its total at some date (a void
|
||||
/// under a payment that stands; re-instating a payment beside
|
||||
@@ -2284,13 +2287,21 @@ impl Ledger {
|
||||
)));
|
||||
}
|
||||
if !crate::parties::is_replaying() {
|
||||
if date < original.date() {
|
||||
return Err(LedgerError::ReversalBeforeOriginal {
|
||||
entry,
|
||||
original: original.date(),
|
||||
date,
|
||||
});
|
||||
}
|
||||
self.check_document_reversal(original, date)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`Self::check_reversal`] SCENARIOS 6 and 7: a reversal of an entry
|
||||
/// carrying documents' lines.
|
||||
/// [`Self::check_reversal`] SCENARIO 7: a reversal of an entry
|
||||
/// carrying documents' lines (the date floor, SCENARIO 6, is checked
|
||||
/// before this runs).
|
||||
fn check_document_reversal(
|
||||
&self,
|
||||
original: &JournalEntry,
|
||||
@@ -2307,16 +2318,8 @@ impl Ledger {
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(&(first, _)) = moves.first() else {
|
||||
if moves.is_empty() {
|
||||
return Ok(());
|
||||
};
|
||||
if date < original.date() {
|
||||
return Err(LedgerError::DocumentReversalBeforeOriginal {
|
||||
entry: original.id(),
|
||||
document: first.to_string(),
|
||||
original: original.date(),
|
||||
date,
|
||||
});
|
||||
}
|
||||
for (doc, by) in moves {
|
||||
self.check_item_bounds(doc, &[(date, by)])?;
|
||||
|
||||
@@ -133,7 +133,12 @@ pub(crate) fn refusal(e: &LedgerError) -> String {
|
||||
LedgerError::DuplicateAccountCode(_) => "code_taken",
|
||||
LedgerError::TaxCategoryRequired { .. } => "tax_category_required",
|
||||
LedgerError::DepreciationPastDisposal(_) => "depreciation_past_disposal",
|
||||
LedgerError::AssetEntryIrreversible(..) => "entry_irreversible",
|
||||
// A reversal dated before its original (D-73) is the examples'
|
||||
// "entry_irreversible" too: bookspec's depreciation example words
|
||||
// the refusal that way, whichever engine check makes it.
|
||||
LedgerError::AssetEntryIrreversible(..) | LedgerError::ReversalBeforeOriginal { .. } => {
|
||||
"entry_irreversible"
|
||||
}
|
||||
LedgerError::AssetAlreadyDisposed(_) => "already_disposed",
|
||||
LedgerError::InvalidDepreciationPeriod(_) => "invalid_depreciation_period",
|
||||
LedgerError::InvalidSchedule(_) => "invalid_schedule",
|
||||
|
||||
@@ -218,7 +218,9 @@ impl Model {
|
||||
return false;
|
||||
};
|
||||
let reversed_already = self.posted.iter().any(|e| e.reversal_of == Some(entry));
|
||||
if reversed_already || orig.closes || self.closed_on(date) {
|
||||
// D-73 (bookspec BS-ledger-5): a correction is dated on or after
|
||||
// what it corrects.
|
||||
if reversed_already || orig.closes || self.closed_on(date) || date < orig.date {
|
||||
return false;
|
||||
}
|
||||
let lines = orig
|
||||
|
||||
@@ -960,11 +960,19 @@ fn a_reinstated_run_counts_and_is_live() {
|
||||
}
|
||||
|
||||
/// A reversal dated before its run: between the two dates the books carry
|
||||
/// −100.00, as the trial balance does (review R2).
|
||||
/// −100.00, as the trial balance does (review R2). No command can write one
|
||||
/// any more (D-73: a reversal is dated on or after its original, so
|
||||
/// `reverse_entry` refuses it), but a journal an earlier version wrote holds
|
||||
/// them and replays as it was (B-28): this test replays one.
|
||||
#[test]
|
||||
fn a_reversal_dated_before_its_run_matches_the_trial_balance() {
|
||||
let (mut l, a, id, e) = one_run();
|
||||
l.reverse_entry(e, date(2026, 1, 15), "early").unwrap();
|
||||
assert!(matches!(
|
||||
l.reverse_entry(e, date(2026, 1, 15), "early"),
|
||||
Err(LedgerError::ReversalBeforeOriginal { .. })
|
||||
));
|
||||
l.replay_reverse_entry(e, date(2026, 1, 15), "early")
|
||||
.unwrap();
|
||||
let on = date(2026, 1, 20);
|
||||
assert_eq!(l.accumulated_posted(id, on).unwrap(), d("-100.00"));
|
||||
let tb = ledger_core::trial_balance_as_of(&l, on);
|
||||
|
||||
@@ -510,11 +510,11 @@ fn reversal_before_original_refused_for_documents() {
|
||||
.unwrap();
|
||||
assert!(matches!(
|
||||
b.l.reverse_entry(pay, d(2026, 1, 19), "early"),
|
||||
Err(LedgerError::DocumentReversalBeforeOriginal { .. })
|
||||
Err(LedgerError::ReversalBeforeOriginal { .. })
|
||||
));
|
||||
assert!(matches!(
|
||||
b.l.void_document(DocRef::Invoice(inv), d(2026, 1, 9), "early"),
|
||||
Err(LedgerError::DocumentReversalBeforeOriginal { .. })
|
||||
Err(LedgerError::ReversalBeforeOriginal { .. })
|
||||
));
|
||||
// The same day is fine.
|
||||
b.l.reverse_entry(pay, d(2026, 1, 20), "same day").unwrap();
|
||||
|
||||
@@ -1770,17 +1770,11 @@ impl Store {
|
||||
/// - SHOULD refuse, naming the room left
|
||||
/// - NEVER let accumulated depreciation pass the schedule, or cost
|
||||
/// less salvage.
|
||||
/// 5. IF it is a depreciation run or a schedule month's posting, or a
|
||||
/// reversal in the chain of one, and `date` is before the entry's
|
||||
/// own date:
|
||||
/// - SHOULD refuse
|
||||
/// - NEVER carry a correction at month ends the entry it corrects
|
||||
/// never reached (a run of March reversed on Jan 31 would leave
|
||||
/// January and February with negative depreciation, and a
|
||||
/// disposal in February clearing what they don't carry)
|
||||
/// BECAUSE a correction comes after what it corrects (B-9, Pacioli
|
||||
/// ch. 31: "after you have made this correction"). Commands only:
|
||||
/// a journal an earlier version wrote replays as it was (B-28).
|
||||
/// 5. (the date floor: a reversal dated before the entry it
|
||||
/// reverses is refused for every entry, by `Ledger::check_reversal`
|
||||
/// with `ReversalBeforeOriginal`, D-73; it was this store's check
|
||||
/// for runs and schedule months alone. A journal an earlier
|
||||
/// version wrote replays as it was, B-28.)
|
||||
/// 6. Otherwise: a run of an active asset is un-posted (its month is
|
||||
/// due again, caught up by the next run).
|
||||
/// ```
|
||||
@@ -1797,18 +1791,6 @@ impl Store {
|
||||
.copied()
|
||||
.unwrap_or(entry);
|
||||
let refuse = |why: String| Err(LedgerError::AssetEntryIrreversible(entry, why).into());
|
||||
// SCENARIO 5: the date of the entry reversed (it ends its chain).
|
||||
let dated = self
|
||||
.ledger
|
||||
.get_entry(entry)
|
||||
.map(ledger_core::JournalEntry::date);
|
||||
let before_it = dated.filter(|&d| date < d);
|
||||
if let (Some(on), Some((sid, month))) = (before_it, self.ledger.schedule_posting(top)) {
|
||||
return Err(LedgerError::InvalidSchedule(format!(
|
||||
"entry {entry} (schedule {sid}'s {month}) is dated {on}: a reversal of it can't be dated before it, on {date}"
|
||||
))
|
||||
.into());
|
||||
}
|
||||
let payloads = |t: &str| -> Result<Vec<Value>, StoreError> {
|
||||
let mut stmt = self
|
||||
.conn
|
||||
@@ -1835,11 +1817,6 @@ impl Store {
|
||||
}
|
||||
let asset_id = get_u64(&p, "asset_id")?;
|
||||
let period = get_str(&p, "period")?;
|
||||
if let Some(on) = before_it {
|
||||
return refuse(format!(
|
||||
"it is dated {on}, and a reversal of asset {asset_id}'s depreciation for {period} can't be dated before it, on {date}"
|
||||
));
|
||||
}
|
||||
if self
|
||||
.ledger
|
||||
.get_asset(asset_id)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
//! A reversal is dated on or after the entry it reverses, for every kind of
|
||||
//! entry (D-73, 2026-11-08; rules.md B-9; bookspec BS-ledger-5): a
|
||||
//! correction comes after what it corrects. A journal an earlier version
|
||||
//! wrote may hold one dated before its original, and it opens as it was
|
||||
//! (B-28: bounds bind new commands, never replay).
|
||||
//!
|
||||
//! ```text
|
||||
//! GOAL: no new reversal precedes its original; no old one stops a journal
|
||||
//! from opening, or moves a figure.
|
||||
//! SOURCE: docs/spec/rules.md B-9, B-28; plan/served.md D-73.
|
||||
//! ```
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use ledger_core::reports::trial_balance;
|
||||
use ledger_core::{AccountType, Currency, LedgerError, Money, Side};
|
||||
use ledger_store::{JournalWriter, Store, StoreError};
|
||||
use rust_decimal::Decimal;
|
||||
use serde_json::json;
|
||||
use std::path::PathBuf;
|
||||
|
||||
struct TestDir(PathBuf);
|
||||
|
||||
impl std::ops::Deref for TestDir {
|
||||
type Target = std::path::Path;
|
||||
fn deref(&self) -> &std::path::Path {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestDir {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_dir(name: &str) -> TestDir {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"wanderbooks-store-revdates-{name}-{}",
|
||||
std::process::id()
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
TestDir(dir)
|
||||
}
|
||||
|
||||
fn d(y: i32, m: u32, day: u32) -> NaiveDate {
|
||||
NaiveDate::from_ymd_opt(y, m, day).unwrap()
|
||||
}
|
||||
|
||||
fn usd(n: i64) -> Money {
|
||||
Money::new(Decimal::new(n, 2), Currency::USD)
|
||||
}
|
||||
|
||||
/// Books with one plain posted entry: rent paid in cash, 100.00, on
|
||||
/// 2026-03-10. Returns (dir, store, rent, cash, entry).
|
||||
fn books(name: &str) -> (TestDir, Store, u64, u64, u64) {
|
||||
let dir = test_dir(name);
|
||||
let mut s = Store::create(&dir, Currency::USD).unwrap();
|
||||
let rent = s
|
||||
.add_account("6000", "Rent", AccountType::Expense, None, false)
|
||||
.unwrap();
|
||||
let cash = s
|
||||
.add_account("1000", "Cash", AccountType::Asset, None, false)
|
||||
.unwrap();
|
||||
let e = s.create_entry(d(2026, 3, 10), "March rent").unwrap();
|
||||
s.add_line(e, rent, Side::Debit, usd(10_000)).unwrap();
|
||||
s.add_line(e, cash, Side::Credit, usd(10_000)).unwrap();
|
||||
s.post_entry(e).unwrap();
|
||||
(dir, s, rent, cash, e)
|
||||
}
|
||||
|
||||
/// A plain entry's reversal dated before it is refused, by the check the
|
||||
/// preview uses and by the command alike, and nothing is journaled; the
|
||||
/// same day and later are taken.
|
||||
#[test]
|
||||
fn a_plain_entrys_reversal_is_not_dated_before_it() {
|
||||
let (_dir, mut s, rent, cash, e) = books("plain");
|
||||
let head = s.head();
|
||||
let tb = trial_balance(s.ledger());
|
||||
let before = (tb.total_debits, tb.total_credits);
|
||||
for early in [d(2026, 3, 9), d(2026, 1, 1)] {
|
||||
assert!(matches!(
|
||||
s.check_reverse_entry(e, early),
|
||||
Err(StoreError::Ledger(LedgerError::ReversalBeforeOriginal { entry, original, date }))
|
||||
if entry == e && original == d(2026, 3, 10) && date == early
|
||||
));
|
||||
assert!(matches!(
|
||||
s.reverse_entry(e, early, "early"),
|
||||
Err(StoreError::Ledger(
|
||||
LedgerError::ReversalBeforeOriginal { .. }
|
||||
))
|
||||
));
|
||||
}
|
||||
assert_eq!(s.head(), head, "a refused reversal journals nothing");
|
||||
let tb = trial_balance(s.ledger());
|
||||
assert_eq!((tb.total_debits, tb.total_credits), before);
|
||||
assert_eq!(s.ledger().account_movement(rent), Decimal::new(10_000, 2));
|
||||
// The same day is fine, and the books net to nothing.
|
||||
s.check_reverse_entry(e, d(2026, 3, 10)).unwrap();
|
||||
let r = s.reverse_entry(e, d(2026, 3, 10), "same day").unwrap();
|
||||
assert_eq!(s.ledger().account_movement(rent), Decimal::ZERO);
|
||||
assert_eq!(s.ledger().account_movement(cash), Decimal::ZERO);
|
||||
// Reversing the reversal (re-instating) is a correction of it too: it
|
||||
// can't precede the reversal, and may follow it.
|
||||
assert!(matches!(
|
||||
s.reverse_entry(r, d(2026, 3, 9), "early"),
|
||||
Err(StoreError::Ledger(
|
||||
LedgerError::ReversalBeforeOriginal { .. }
|
||||
))
|
||||
));
|
||||
s.reverse_entry(r, d(2026, 3, 11), "later").unwrap();
|
||||
assert_eq!(s.ledger().account_movement(rent), Decimal::new(10_000, 2));
|
||||
}
|
||||
|
||||
/// A journal an earlier version wrote, holding a reversal dated before its
|
||||
/// original, opens exactly as it was: same figures, chain verified, in the
|
||||
/// writer and again after a snapshot-less reopen (B-28).
|
||||
#[test]
|
||||
fn a_journal_with_an_earlier_dated_reversal_opens_as_it_was() {
|
||||
let (dir, s, rent, cash, e) = books("replay");
|
||||
let next = s.ledger().next_entry_id();
|
||||
drop(s);
|
||||
// What the old behaviour journaled: the mirror of the entry, dated
|
||||
// 2026-03-01, nine days before it.
|
||||
let mut w = JournalWriter::open(&dir.join(ledger_store::JOURNAL_FILE)).unwrap();
|
||||
let line = |account: u64, side: &str| json!({"account": account, "side": side, "amount": "100.00", "currency": "USD"});
|
||||
w.append(
|
||||
"entry.reversed",
|
||||
json!({"id": next, "reverses": e, "date": "2026-03-01",
|
||||
"description": "backdated by an earlier version",
|
||||
"lines": [line(rent, "credit"), line(cash, "debit")]}),
|
||||
)
|
||||
.unwrap();
|
||||
drop(w);
|
||||
|
||||
let store = Store::open(&dir).unwrap();
|
||||
store.verify().unwrap();
|
||||
let l = store.ledger();
|
||||
let r = l.get_entry(next).unwrap();
|
||||
assert_eq!(r.date(), d(2026, 3, 1));
|
||||
assert_eq!(r.reversal_of(), Some(e));
|
||||
assert_eq!(l.account_movement(rent), Decimal::ZERO);
|
||||
assert_eq!(l.account_movement(cash), Decimal::ZERO);
|
||||
let tb = trial_balance(l);
|
||||
assert_eq!(tb.total_debits, tb.total_credits);
|
||||
// The old entry stands reversed, and the books still refuse a new
|
||||
// backdated reversal of anything.
|
||||
assert!(!l.in_effect(e));
|
||||
assert!(matches!(
|
||||
store.check_reverse_entry(next, d(2026, 2, 1)),
|
||||
Err(StoreError::Ledger(
|
||||
LedgerError::ReversalBeforeOriginal { .. }
|
||||
))
|
||||
));
|
||||
}
|
||||
@@ -584,9 +584,9 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`.
|
||||
and a reversal whose reversal would post a depreciation period or a
|
||||
schedule month a second time (naming the entry that posts it now), or
|
||||
re-instate a run a later run caught up (carrying the books past the
|
||||
schedule); and a reversal of a depreciation run or a schedule month's
|
||||
posting (or of a reversal in its chain) dated before that entry's own
|
||||
date (a correction comes after what it corrects, B-9).
|
||||
schedule); and a reversal of any entry dated before that entry's own
|
||||
date (a correction comes after what it corrects, B-9, D-73; the preview
|
||||
refuses the same way, and books written before D-73 open as they were).
|
||||
- `books.get_entry { entry_id }` → full entry with lines (each `{
|
||||
account_id, code, name, side, amount, class_id?, project? }`: a tagged
|
||||
line's project, its id and name), receipts, and
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ in CI that the floor never falls between commits.
|
||||
| Trial balance as of a date | Reports → Trial Balance (as of) | done | hand-verified fixture; golden-covered (`tests/golden_reports.rs`, the fixture company extended with a three-leg entry, a January close and a February entry; `golden/trial_balance_as_of.json`, `golden_trial_balance_as_of`; worksheet `plan/golden-worksheets/trial-balance-as-of.md`) |
|
||||
| Statement of changes in members' equity | Reports → Statement of Changes in Equity | done | hand-verified two-member fixture incl. rounding and a close; golden-covered (`golden/members_equity_two_member.json`, `statements.rs::golden_members_equity_two_member`; worksheet `plan/golden-worksheets/members_equity_two_member.md`) |
|
||||
| Tax line mapping + tax summary | Accounts → Tax line mapping; Tax reports | done | hand-verified fixture (50% meals, nondeductible, contra income); golden-covered (`golden/tax_summary_form_1065.json`, `tax.rs::golden_tax_summary_form_1065`; worksheet `plan/golden-worksheets/tax_summary_form_1065.md`) |
|
||||
| Reversing entries | Reverse transaction | done | linked via `reversal_of` |
|
||||
| Reversing entries | Reverse transaction | done | linked via `reversal_of`; dated on or after its original, every kind of entry (D-73) |
|
||||
| Canonical report snapshots (JSON) | — (our oracle format) | done | `reports::snapshot` |
|
||||
| Fixed-asset register + straight-line depreciation | Fixed Asset register | done | `assets.rs`; golden-covered schedule; idempotent runs; disposal with gain/loss; posted (the books') vs scheduled, in-service vs acquired dates, the §723, depreciable and §704(c) figures (P3) |
|
||||
| Cash flow statement (direct, with the reconciliation schedule and noncash disclosures) | Reports → Cash Flow | done | R-FUTURE-3; rules.md B-14 (P3 defect 1) |
|
||||
|
||||
@@ -114,6 +114,24 @@ an entry on the opposite side under the same account."
|
||||
`reversal_of`). **Checked:** Kani `reversal_mirrors`, `reversal_cancels`;
|
||||
Lean `accepted_reversal_iff`, `movement_with_reversal`.
|
||||
|
||||
**Pick (D-73, the owner, 2026-11-08):** every reversal is dated on or after
|
||||
the entry it reverses, for every kind of entry (it was enforced only for
|
||||
document reversals and for schedule and depreciation runs): a correction
|
||||
comes after what it corrects. The same day is allowed. New commands only:
|
||||
a journal an earlier version wrote may hold a reversal dated before its
|
||||
original, and it replays as it was (B-28).
|
||||
**Enforced:** `Ledger::check_reversal` (SCENARIO 6) refuses with
|
||||
`ReversalBeforeOriginal`, ahead of the document and schedule checks; the
|
||||
store's `check_reverse_entry` and so `books.reverse_entry` (preview and
|
||||
post alike) and every document void go through it, and replay is exempt
|
||||
(`crate::parties::is_replaying`). **Checked:** store
|
||||
`a_plain_entrys_reversal_is_not_dated_before_it`,
|
||||
`a_journal_with_an_earlier_dated_reversal_opens_as_it_was`; core
|
||||
`reversal_before_original_refused_for_documents`,
|
||||
`a_reversal_dated_before_its_run_matches_the_trial_balance` (replayed);
|
||||
the model oracle `the_ledger_matches_its_model` (its `reverse` requires
|
||||
the date, as BS-ledger-5 does).
|
||||
|
||||
## B-10 An entry is reversed at most once; a closing entry never
|
||||
|
||||
**bookspec:** `BS-ledger-6`
|
||||
|
||||
@@ -1446,6 +1446,7 @@ a bookspec example (`bookspec/examples/`, P13, D-34).
|
||||
| Every order of runs, reversals (any day, before an entry's own included), re-runs, re-instatements, disposals and closes on one asset keeps the books right: refusals journal nothing; at every month end before the disposal the expense is the accumulated depreciation and within the schedule; one run in effect per month; a disposal's month and the end at the schedule through its day, accumulated 0.00, the gain proceeds less book value; an active asset run month by month past its life takes exactly cost less salvage (P3 review round 2) | store `asset_orders.rs` `every_order_of_runs_reversals_disposals_and_closes_keeps_the_books_right` (exhaustive, three commands deep; four and five with `WB_ORDERS_DEPTH`, run clean 2026-10-21), `prop_any_sequence_keeps_the_books_right` (64 cases, up to 9 commands, any day) |
|
||||
| The viewer reads an asset as the store does, whatever the runs, reversals and disposals: what the books carry, each finished month's status against a run of it, what is unposted (P3 review round 2) | GUI `prop_the_viewer_reads_an_asset_as_the_store_does` (48 cases), `the_viewer_counts_a_run_reinstated_after_its_rerun_was_reversed` |
|
||||
| A run re-instated after its month was run again and that run reversed still counts: in the store, the disposal and the viewer (P3 review round 2; before, the projection's row named the reversed re-run) | store `a_run_reinstated_after_its_rerun_was_reversed_still_counts`; GUI `the_viewer_counts_a_run_reinstated_after_its_rerun_was_reversed` |
|
||||
| Every reversal is dated on or after its original, any kind of entry (D-73); a journal holding an earlier-dated one still opens with the same figures (B-28): store `reversal_dates.rs` `a_plain_entrys_reversal_is_not_dated_before_it`, `a_journal_with_an_earlier_dated_reversal_opens_as_it_was` |
|
||||
| A depreciation run's or schedule month's reversal can't be dated before the entry it reverses (P3 review round 2: a run of March reversed on Jan 31, then a disposal on Feb 15, ended February with a 1,000.00 debit in accumulated depreciation) | store `a_reversal_dated_before_the_entry_it_reverses_is_refused` |
|
||||
| A disposal waits only until what the runs carry at its month's end is what they carry now, so a late change undone after its month closed lets it through (P3 review round 2; round 1 refused it for ever) | store `a_disposal_is_taken_once_a_late_change_is_undone_after_its_month_closed` |
|
||||
| Depreciation still due when the disposal's month has a run is charged in the disposal entry, never as a second run of the month (P3 review round 2; no store test held it) | store `a_disposal_whose_month_has_run_charges_what_is_still_due_in_its_entry` |
|
||||
|
||||
Reference in new issue
Block a user