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
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user