refactor: rule references cite bookspec ids
Every B-n citation in crates/, docs/, deploy/, scripts/ and .github/ now names its bookspec id BS-<area>-<n> (D-68), via scripts/rewrite-rule-refs.py: the map is parsed from docs/spec/rules.md's index, rules.md-prefixed and bare forms are rewritten, sub-references (rule 11, item 7, INVARIANT 2) survive, and plan/, docs/spec/rules.md and docs/spec/claims/ are untouched. Program-output string literals that cited a rule were reverted by hand so user-visible output and its goldens are unchanged; DatedRule.catalog, metadata no output prints, now holds BS-1099-1. One SOURCE line that cited only 'R-?' now also cites BS-statement-5. Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
1 parent
7a177a3cfc
commit
489360f598
221 files changed
+1706
-1580
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! The audit's journal and the integrity checks (plan P8; rules.md B-45):
|
||||
//! The audit's journal and the integrity checks (plan P8; BS-ledger-13):
|
||||
//! `audit.run`, `receipt.attested`, `entry.reviewed` and `period.attested`,
|
||||
//! what "the current head" means, and the findings only the store can see.
|
||||
//!
|
||||
@@ -7,7 +7,7 @@
|
||||
//! head, so the same books give the same run once, and an
|
||||
//! attestation rests on a head that has not moved.
|
||||
//! SOURCE: IRS Pub. 583 (records); Rev. Proc. 98-25 §5.01 (the audit
|
||||
//! trail); docs/spec/rules.md B-45; DECISION D-9 (the bar), D-53
|
||||
//! trail); BS-ledger-13; DECISION D-9 (the bar), D-53
|
||||
//! (an audit is a run, not a job), IZ-1k (the head).
|
||||
//! INVARIANTS:
|
||||
//! 1. The figure head is the seq of the last journal line that bears on
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! what, and which entry it belongs to.
|
||||
//! SOURCE: plan/served.md P5 step 4 (the only way to "read the journal");
|
||||
//! docs/receipt-store.md (the lines and their payloads);
|
||||
//! docs/spec/rules.md B-26 (no output holds a full TIN).
|
||||
//! BS-partner-2 (no output holds a full TIN).
|
||||
//! INVARIANTS:
|
||||
//! 1. Every line type the store writes has a sentence (test: every
|
||||
//! `format::EVENT_TYPES` entry).
|
||||
|
||||
@@ -36,7 +36,7 @@ pub enum StoreError {
|
||||
AssetDepreciationPosted(u64),
|
||||
|
||||
/// The receipt policy covers the entry and it has no receipt (plan P4,
|
||||
/// I-5; rules.md B-43): refused before anything is journaled.
|
||||
/// I-5; BS-entry-5): refused before anything is journaled.
|
||||
#[error(
|
||||
"entry {} needs a receipt before it posts: {} ({}); attach one with books.attach_receipt",
|
||||
.0.entry_id, .0.reason, .0.policy
|
||||
@@ -69,7 +69,7 @@ pub enum StoreError {
|
||||
/// though the lines after it are the newer version's to check. When
|
||||
/// nothing checks it (it is the last line, or the next has no `prev`
|
||||
/// this version can read), it is either newer or damaged, and the
|
||||
/// message says so (rules.md B-27).
|
||||
/// message says so (BS-format-1).
|
||||
#[error("{}", newer_journal_text(*seq, event_type, need, *verified))]
|
||||
NewerJournal {
|
||||
/// The first line this version can't read.
|
||||
@@ -152,7 +152,7 @@ pub enum StoreError {
|
||||
#[error("store not found at {0}")]
|
||||
NotFound(String),
|
||||
|
||||
/// A write-off with no evidence (rules.md B-41 INVARIANT 1): a bad
|
||||
/// A write-off with no evidence (BS-arap-5 INVARIANT 1): a bad
|
||||
/// debt is deducted on evidence that it is worthless (Treas. Reg.
|
||||
/// §1.166-2), so the books take the write-off only with its file.
|
||||
#[error(
|
||||
@@ -162,8 +162,8 @@ pub enum StoreError {
|
||||
)]
|
||||
WriteOffNeedsEvidence,
|
||||
|
||||
/// An audit or an attestation the books refuse (plan P8; rules.md
|
||||
/// B-45): a stale head, an entry not posted, a receipt not on the
|
||||
/// An audit or an attestation the books refuse (plan P8;
|
||||
/// BS-ledger-13): a stale head, an entry not posted, a receipt not on the
|
||||
/// entry. The words say what to do.
|
||||
#[error("{0}")]
|
||||
AuditRefused(String),
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//! GOAL: every event round-trips: decode(encode(x)) == x, and every line
|
||||
//! written before decisions were kept reads as it always meant.
|
||||
//! SOURCE: plan/served.md 5.2, 5.5 (a legacy null is undetermined);
|
||||
//! rules.md B-27 (an older reader says "newer", never "corrupt").
|
||||
//! BS-format-1 (an older reader says "newer", never "corrupt").
|
||||
//! INVARIANTS:
|
||||
//! 1. vendor.1099_set {vendor_id, form_1099: "nec"|"misc"|
|
||||
//! "not_reportable"|null, reason_kind?, reason?, effective?,
|
||||
@@ -22,7 +22,7 @@
|
||||
//! 4. instrument.added {instrument_id, kind, label, last4?,
|
||||
//! owner_party_id?, account_id}; entry.instrument_set {entry_id,
|
||||
//! instrument_id|null}. Optional keys are left out when absent.
|
||||
//! 5. Decoding checks shape only (rules.md B-28): what a command checks
|
||||
//! 5. Decoding checks shape only (BS-entry-4): what a command checks
|
||||
//! (limits, the chart) stays with the command.
|
||||
//! ```
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
//! checks ([`crate::journal::read_journal_and_format`], and
|
||||
//! [`crate::Snapshot`] line by line).
|
||||
//!
|
||||
//! What every format shares is frozen (rules.md B-27): a line is the
|
||||
//! What every format shares is frozen (BS-format-1): a line is the
|
||||
//! envelope `{seq, ts, type, payload, prev}` and nothing beside it, and
|
||||
//! its hash is the SHA-256 of its canonical JSON (keys sorted, no
|
||||
//! whitespace). A newer format adds its fields inside `payload`. So this
|
||||
@@ -27,7 +27,7 @@
|
||||
//! The other way round, books an older version wrote are in an older
|
||||
//! format: this version reads them as they are, and writes nothing that
|
||||
//! needs a format or feature they haven't declared until the owner says
|
||||
//! go (the format upgrade, rules.md B-27, plan/served.md 3.9, D-39:
|
||||
//! go (the format upgrade, BS-format-1, plan/served.md 3.9, D-39:
|
||||
//! [`JournalFormat::upgrade`], [`current`]). New books declare this
|
||||
//! version's whole format as they are created.
|
||||
|
||||
@@ -43,7 +43,7 @@ pub const SUPPORTED_JOURNAL_FORMAT: u32 = 2;
|
||||
/// unknown), or a field or value on an event type it knows (which it
|
||||
/// would misread silently). The books declare it (`journal.format_set`)
|
||||
/// before their first such line, so the older version stops there instead
|
||||
/// (rules.md B-27). Every one is declared at once: by new books as they
|
||||
/// (BS-format-1). Every one is declared at once: by new books as they
|
||||
/// are created, and by older books at their format upgrade ([`current`]);
|
||||
/// until then a write that needs one is refused.
|
||||
pub const KNOWN_FEATURES: &[&str] = &[
|
||||
@@ -72,7 +72,7 @@ pub const KNOWN_FEATURES: &[&str] = &[
|
||||
/// Feature: `period.closed` closes to members with `"rounding":
|
||||
/// "cumulative_since"` and `since_seq`, the count of members closes
|
||||
/// starting at the first since the members or shares last changed (P3
|
||||
/// defect 17, rules.md B-13). An older version would call the rounding
|
||||
/// defect 17, BS-partner-1). An older version would call the rounding
|
||||
/// unknown, or (before the format gate) replay the close under the run
|
||||
/// rule, which can split it differently.
|
||||
pub const MEMBERS_CUMULATIVE: &str = "members_cumulative";
|
||||
@@ -136,14 +136,14 @@ pub const DISPOSAL_BEFORE_SERVICE: &str = "disposal_before_service";
|
||||
|
||||
/// Feature: an `asset.depreciation_posted` whose amount is not its month's
|
||||
/// own depreciation: earlier months skipped or reversed caught up in it, or
|
||||
/// a final month left over past the life (P3's run rule, B-15). An earlier
|
||||
/// a final month left over past the life (P3's run rule, BS-asset-1). An earlier
|
||||
/// version reads every run as its month's own: it would show the caught-up
|
||||
/// months as not yet run, and running them post their depreciation twice
|
||||
/// (P3 review, 2026-10-21).
|
||||
pub const DEPRECIATION_CATCH_UP: &str = "depreciation_catch_up";
|
||||
|
||||
/// The feature `party.creditor_set` lines need: a party named the
|
||||
/// creditor of a liability (rules.md B-35, P3 defect 24).
|
||||
/// creditor of a liability (BS-partner-3, P3 defect 24).
|
||||
pub const PARTY_CREDITORS: &str = "party_creditors";
|
||||
|
||||
/// Payment methods (`instrument.added`) and the entries tagged with one
|
||||
@@ -171,7 +171,7 @@ pub const SCHEDULE_CONVENTION: &str = "schedule_convention";
|
||||
/// with the value at contribution and the §704(c) method (P3, defect 13).
|
||||
pub const ASSET_BASIS: &str = "asset_basis";
|
||||
|
||||
/// Feature: projects (rules.md B-37): `project.set`, a new event type (a
|
||||
/// Feature: projects (BS-statement-5): `project.set`, a new event type (a
|
||||
/// class's project facts); `attachment.linked` to the subject kind
|
||||
/// `project` (an older version would call it corrupt); and
|
||||
/// `decision.recorded` with `projects` (an older version would drop them
|
||||
@@ -179,7 +179,7 @@ pub const ASSET_BASIS: &str = "asset_basis";
|
||||
pub const PROJECTS: &str = "projects";
|
||||
|
||||
/// Feature: an `invoice.created` or `bill.created` line naming its project
|
||||
/// (`class_id`, rules.md B-37 item 8). An older version would restore the
|
||||
/// (`class_id`, BS-statement-5 item 8). An older version would restore the
|
||||
/// document without its lines' projects, silently. Its own feature, not
|
||||
/// `projects`': books that consented to projects before it existed must
|
||||
/// consent again before a document names one.
|
||||
@@ -187,7 +187,7 @@ pub const DOCUMENT_LINE_PROJECTS: &str = "document_line_projects";
|
||||
|
||||
/// Feature: an `invoice.payment_received` or `bill.paid` accepted only
|
||||
/// because an earlier payment on its document was reversed (plan P4b S1,
|
||||
/// D-45; rules.md B-38): this version reads a document's figures from the
|
||||
/// D-45; BS-arap-2): this version reads a document's figures from the
|
||||
/// ledger lines that stand, so a reversed payment no longer counts and the
|
||||
/// right one is taken. An older version adds every payment event to the
|
||||
/// document's paid amount, standing or not: it would replay the new
|
||||
@@ -211,7 +211,7 @@ pub const DOCUMENTS_V2: &str = "documents_v2";
|
||||
/// payment pays back), and `attachment.withdrawn` carrying `duplicate_of`.
|
||||
/// An older version doesn't know those event types, or would withdraw a
|
||||
/// duplicate without saying what it duplicates; it stops at the
|
||||
/// declaration instead (rules.md B-27, B-44).
|
||||
/// declaration instead (BS-format-1, BS-ledger-12).
|
||||
pub const ATTACHMENT_TEXT: &str = "attachment_text";
|
||||
|
||||
/// Feature: `drafts_v2` (plan P4, D-52): `entry.draft_state_set` (a draft
|
||||
@@ -220,7 +220,7 @@ pub const ATTACHMENT_TEXT: &str = "attachment_text";
|
||||
/// event types: it would refuse them as unknown, or, replaying around
|
||||
/// them, keep a discarded draft that blocks a period's close and call a
|
||||
/// waiting draft one being built; it stops at the declaration instead
|
||||
/// (rules.md B-27, B-43).
|
||||
/// (BS-format-1, BS-entry-5).
|
||||
pub const DRAFTS_V2: &str = "drafts_v2";
|
||||
|
||||
/// Feature: `source_revisions` (plan P5): `convention.source_revised`,
|
||||
@@ -229,7 +229,7 @@ pub const DRAFTS_V2: &str = "drafts_v2";
|
||||
/// leaving its text as it was. An older version doesn't know those event
|
||||
/// types: it would refuse them as unknown, or, replaying around them,
|
||||
/// show the old source as the decision's authority; it stops at the
|
||||
/// declaration instead (rules.md B-27).
|
||||
/// declaration instead (BS-format-1).
|
||||
pub const SOURCE_REVISIONS: &str = "source_revisions";
|
||||
|
||||
/// Feature: `audits` (plan P8): `audit.run` (a programme of checks run
|
||||
@@ -240,7 +240,7 @@ pub const SOURCE_REVISIONS: &str = "source_revisions";
|
||||
/// waits for an audit (`policy.cpa_package_requires_audit`). An older
|
||||
/// version doesn't know those event types or settings; it stops at the
|
||||
/// declaration instead of dropping the claims a handoff rests on
|
||||
/// (rules.md B-27, B-45).
|
||||
/// (BS-format-1, BS-ledger-13).
|
||||
pub const AUDITS: &str = "audits";
|
||||
|
||||
/// The line type that declares the journal format.
|
||||
@@ -364,7 +364,7 @@ impl JournalFormat {
|
||||
/// ```text
|
||||
/// GOAL: an older wanderbooks never misreads newer books, and never
|
||||
/// calls them corrupt.
|
||||
/// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate).
|
||||
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
|
||||
/// INVARIANTS:
|
||||
/// 1. Only lines that parsed, chained and kept their seq reach the
|
||||
/// gate: damage stays JournalCorrupt.
|
||||
@@ -496,8 +496,8 @@ impl JournalFormat {
|
||||
}
|
||||
}
|
||||
|
||||
/// The format upgrade books in this format wait for, if any (rules.md
|
||||
/// B-27, plan/served.md 3.9, D-39).
|
||||
/// The format upgrade books in this format wait for, if any (
|
||||
/// BS-format-1, plan/served.md 3.9, D-39).
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: books an older version wrote are never moved to a newer
|
||||
@@ -587,7 +587,7 @@ fn declared_knowing(line: &JournalLine, known: &[&str]) -> Result<JournalFormat,
|
||||
/// The refusal for a line of a type this version knows that holds a
|
||||
/// value only a newer version writes: a setting key, a convention kind
|
||||
/// (`need` says which). Never "corrupt": the books are fine, this reader
|
||||
/// is old (rules.md B-27).
|
||||
/// is old (BS-format-1).
|
||||
pub(crate) fn newer_content(line: &JournalLine, need: String) -> StoreError {
|
||||
newer(line, need)
|
||||
}
|
||||
@@ -598,7 +598,7 @@ pub(crate) fn unknown_type(line: &JournalLine) -> StoreError {
|
||||
}
|
||||
|
||||
/// The gate for one line as read: a line with a key beside the envelope's
|
||||
/// is newer (rules.md B-27: this version never drops a key it can't
|
||||
/// is newer (BS-format-1: this version never drops a key it can't
|
||||
/// read), and any other goes to `admit` (JournalFormat::admit).
|
||||
pub(crate) fn gate(
|
||||
read: &ReadLine,
|
||||
@@ -634,7 +634,7 @@ fn newer(line: &JournalLine, need: String) -> StoreError {
|
||||
/// ```text
|
||||
/// GOAL: damage is never reported as books from a newer wanderbooks, and
|
||||
/// books from a newer wanderbooks never as damage.
|
||||
/// SOURCE: rules.md B-27 (the envelope and its hash are frozen across
|
||||
/// SOURCE: BS-format-1 (the envelope and its hash are frozen across
|
||||
/// formats); docs/receipt-store.md "Line format" (a line's hash is
|
||||
/// checked only by the next line's prev).
|
||||
/// INVARIANTS:
|
||||
@@ -848,7 +848,7 @@ mod tests {
|
||||
/// The version the live books run (every feature through `projects`)
|
||||
/// stops at a declaration of `document_line_projects` as newer, never
|
||||
/// restoring an invoice or bill without its lines' projects; and books
|
||||
/// that declared `projects` alone still wait for it (B-27, D-39).
|
||||
/// that declared `projects` alone still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn document_line_projects_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DOCUMENT_LINE_PROJECTS));
|
||||
@@ -887,7 +887,7 @@ mod tests {
|
||||
/// `document_line_projects`) stops at a declaration of
|
||||
/// `document_standing` as newer, never adding a payment taken after a
|
||||
/// reversal on top of the reversed one; and books that declared every
|
||||
/// earlier feature still wait for it (B-27, D-39).
|
||||
/// earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn document_standing_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DOCUMENT_STANDING));
|
||||
@@ -921,7 +921,7 @@ mod tests {
|
||||
/// The version before P6 (every feature through `documents_v2`) stops
|
||||
/// at a declaration of `attachment_text` as newer, never dropping a
|
||||
/// file's extraction, annotations or settlements; and books that
|
||||
/// declared every earlier feature still wait for it (B-27, D-39).
|
||||
/// declared every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn attachment_text_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&ATTACHMENT_TEXT));
|
||||
@@ -956,7 +956,7 @@ mod tests {
|
||||
/// `document_standing`) stops at a declaration of `documents_v2` as
|
||||
/// newer, never restoring a party's email or default terms as absent
|
||||
/// (or a document without its numbers, once S4.3 writes them); books
|
||||
/// that declared every earlier feature still wait for it (B-27, D-39).
|
||||
/// that declared every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn documents_v2_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DOCUMENTS_V2));
|
||||
@@ -991,7 +991,7 @@ mod tests {
|
||||
/// stops at a declaration of `drafts_v2` as newer, never keeping a
|
||||
/// discarded draft or calling a waiting one a draft being built; and
|
||||
/// books that declared every earlier feature still wait for it
|
||||
/// (B-27, D-39).
|
||||
/// (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn drafts_v2_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DRAFTS_V2));
|
||||
@@ -1024,7 +1024,7 @@ mod tests {
|
||||
|
||||
/// The version before P5 (every feature through `drafts_v2`) stops at a
|
||||
/// declaration of `source_revisions` as newer, and books that declared
|
||||
/// every earlier feature still wait for it (B-27, D-39).
|
||||
/// every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn source_revisions_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&SOURCE_REVISIONS));
|
||||
@@ -1057,7 +1057,7 @@ mod tests {
|
||||
|
||||
/// The version before P8 stops at a declaration of `audits` as newer,
|
||||
/// never dropping an attestation a handoff rests on; books that
|
||||
/// declared every earlier feature still wait for it (B-27, D-39).
|
||||
/// declared every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn audits_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&AUDITS));
|
||||
@@ -1221,7 +1221,7 @@ mod tests {
|
||||
/// A format newer than this version reads is newer whatever shape the
|
||||
/// rest of its declaration takes, and however large its number: a
|
||||
/// newer format may define its features differently, so they are
|
||||
/// judged only for a format this version reads (rules.md B-27).
|
||||
/// judged only for a format this version reads (BS-format-1).
|
||||
#[test]
|
||||
fn a_newer_format_is_newer_whatever_its_features_look_like() {
|
||||
let mut f = JournalFormat::default();
|
||||
|
||||
@@ -71,7 +71,7 @@ fn sort_value(v: &Value) -> Value {
|
||||
}
|
||||
|
||||
/// The keys of a journal line, the same in every journal format
|
||||
/// (rules.md B-27): a newer format adds its fields inside `payload`, never
|
||||
/// (BS-format-1): a newer format adds its fields inside `payload`, never
|
||||
/// beside it, and a line's hash is always the SHA-256 of its canonical
|
||||
/// JSON ([`canonical_json`]), whatever the format.
|
||||
pub const ENVELOPE_KEYS: [&str; 5] = ["payload", "prev", "seq", "ts", "type"];
|
||||
@@ -84,7 +84,7 @@ impl JournalLine {
|
||||
/// hash chain covers) is a fixed point.
|
||||
/// SOURCE: R-2 (no floats in money paths); found by fuzz_journal_line
|
||||
/// (2026-10-13): a float payload re-canonicalized differently;
|
||||
/// rules.md B-27 (the envelope is frozen).
|
||||
/// BS-format-1 (the envelope is frozen).
|
||||
/// INVARIANTS:
|
||||
/// 1. NEVER accepts a floating-point number anywhere in the line:
|
||||
/// amounts are decimal strings and ids are integers.
|
||||
@@ -267,7 +267,7 @@ pub fn read_and_verify_journal(path: &Path) -> Result<Vec<JournalLine>, StoreErr
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: books read whole and verified, or refused with the reason.
|
||||
/// SOURCE: docs/receipt-store.md "Line format"; rules.md B-27.
|
||||
/// SOURCE: docs/receipt-store.md "Line format"; BS-format-1.
|
||||
/// INVARIANTS:
|
||||
/// 1. Line by line, in order: parse, seq, chain, then the format gate.
|
||||
/// 2. Damage before the first line this version can't read is
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! INVARIANTS:
|
||||
//! 1. A payload missing a field, or with a field of the wrong type, is
|
||||
//! JournalCorrupt; optional fields may be absent or null.
|
||||
//! 2. Decoding checks shape only (rules.md B-28): what a command checks
|
||||
//! 2. Decoding checks shape only (BS-entry-4): what a command checks
|
||||
//! (limits, the chart) stays with the command.
|
||||
//! ```
|
||||
|
||||
@@ -301,7 +301,7 @@ pub fn decision_recorded_of(p: &Value) -> Result<(u64, NewDecision), StoreError>
|
||||
|
||||
/// `project.set {id, name, status, kind?, description?, party_id?,
|
||||
/// started_on?, ended_on?, links?, notes?}`: a class's whole project
|
||||
/// record (rules.md B-37; journal feature `projects`). Every optional key
|
||||
/// record (BS-statement-5; journal feature `projects`). Every optional key
|
||||
/// is left out when empty, so the payload is canonical.
|
||||
pub fn project_set(id: ClassId, name: &str, f: &ProjectFacts) -> Value {
|
||||
let mut o = Map::new();
|
||||
@@ -322,7 +322,7 @@ pub fn project_set(id: ClassId, name: &str, f: &ProjectFacts) -> Value {
|
||||
|
||||
/// Read a `project.set`: `(id, name, facts)`. A missing or mistyped key is
|
||||
/// corrupt; a status or kind this version doesn't know is newer (a newer
|
||||
/// version wrote it, rules.md B-27).
|
||||
/// version wrote it, BS-format-1).
|
||||
pub fn project_set_of(
|
||||
line: &crate::journal::JournalLine,
|
||||
) -> Result<(ClassId, String, ProjectFacts), StoreError> {
|
||||
@@ -463,7 +463,7 @@ pub fn invoice_sent(invoice: u64, s: &Sent) -> Value {
|
||||
}
|
||||
|
||||
/// Read an `invoice.sent`: `(invoice, send)`. A channel or kind this
|
||||
/// version doesn't know is newer, never corrupt (rules.md B-27).
|
||||
/// version doesn't know is newer, never corrupt (BS-format-1).
|
||||
pub fn invoice_sent_of(line: &JournalLine) -> Result<(u64, Sent), StoreError> {
|
||||
const E: &str = "invoice.sent";
|
||||
let p = &line.payload;
|
||||
@@ -487,7 +487,7 @@ pub fn invoice_sent_of(line: &JournalLine) -> Result<(u64, Sent), StoreError> {
|
||||
))
|
||||
}
|
||||
|
||||
/// A bad-debt write-off as journaled (plan P4b S7; rules.md B-41):
|
||||
/// A bad-debt write-off as journaled (plan P4b S7; BS-arap-5):
|
||||
/// `invoice.written_off {invoice_id, entry_id, date, amount, reason}`.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct WrittenOff {
|
||||
@@ -557,7 +557,7 @@ pub fn text_extracted(
|
||||
|
||||
/// Read an `attachment.text_extracted`: `(attachment_id, text_sha256,
|
||||
/// extractor, version, pages, status)`. A status this version doesn't know
|
||||
/// is newer (B-27: never "corrupt" for newer).
|
||||
/// is newer (BS-format-1: never "corrupt" for newer).
|
||||
pub fn text_extracted_of(line: &crate::journal::JournalLine) -> Result<TextExtracted, StoreError> {
|
||||
const E: &str = "attachment.text_extracted";
|
||||
let p = &line.payload;
|
||||
@@ -624,7 +624,7 @@ pub fn annotated(a: &Annotation) -> Value {
|
||||
|
||||
/// Read an `attachment.annotated`. A field this version doesn't know, or a
|
||||
/// mistyped one, is judged by its kind: unknown is newer (a later version
|
||||
/// wrote it, B-27), mistyped is corrupt.
|
||||
/// wrote it, BS-format-1), mistyped is corrupt.
|
||||
pub fn annotated_of(line: &crate::journal::JournalLine) -> Result<Annotation, StoreError> {
|
||||
const E: &str = "attachment.annotated";
|
||||
let p = &line.payload;
|
||||
@@ -704,7 +704,7 @@ pub fn draft_state_set(id: u64, state: &DraftState) -> Value {
|
||||
}
|
||||
|
||||
/// Read an `entry.draft_state_set`: `(draft, state)`. A state this
|
||||
/// version doesn't know is newer, never corrupt (rules.md B-27).
|
||||
/// version doesn't know is newer, never corrupt (BS-format-1).
|
||||
pub fn draft_state_set_of(line: &JournalLine) -> Result<(u64, DraftState), StoreError> {
|
||||
const E: &str = "entry.draft_state_set";
|
||||
let p = &line.payload;
|
||||
@@ -748,7 +748,7 @@ pub fn method_json(m: &ledger_core::audit::Method) -> Value {
|
||||
}
|
||||
|
||||
/// Read a method. A key or an effort this version doesn't know is newer
|
||||
/// when a line is at hand (B-27), else corrupt.
|
||||
/// when a line is at hand (BS-format-1), else corrupt.
|
||||
fn method_of(
|
||||
line: Option<&crate::journal::JournalLine>,
|
||||
m: &Value,
|
||||
|
||||
@@ -78,7 +78,7 @@ pub enum ViewerTarget {
|
||||
/// Account code.
|
||||
code: String,
|
||||
/// First date, YYYY-MM-DD. `books.show` always sends both dates,
|
||||
/// resolved (rules.md B-30); `None` only from an earlier writer,
|
||||
/// resolved (BS-period-3); `None` only from an earlier writer,
|
||||
/// which the viewer resolves by the same rule.
|
||||
start: Option<String>,
|
||||
/// Last date, YYYY-MM-DD (see `start`).
|
||||
@@ -91,7 +91,7 @@ pub enum ViewerTarget {
|
||||
/// ar_aging, ap_aging, fixed_asset_register.
|
||||
report: String,
|
||||
/// First date, YYYY-MM-DD. `books.show` always sends both dates,
|
||||
/// resolved (rules.md B-30); `None` only from an earlier writer,
|
||||
/// resolved (BS-period-3); `None` only from an earlier writer,
|
||||
/// which the viewer resolves by the same rule.
|
||||
start: Option<String>,
|
||||
/// Last date, YYYY-MM-DD (see `start`): the as-of day of a report
|
||||
|
||||
@@ -388,7 +388,7 @@ ALTER TABLE asset_depreciation_v13 RENAME TO asset_depreciation;
|
||||
"#,
|
||||
r#"
|
||||
-- v15: a document keeps no figure of its own (plan P4b S1, D-45; rules.md
|
||||
-- B-38): what an invoice or bill has been paid, and its status, are read
|
||||
-- BS-arap-2): what an invoice or bill has been paid, and its status, are read
|
||||
-- from the ledger lines tagged with it, as of any date, and a reversed
|
||||
-- payment no longer counts. The columns that summed its payment events
|
||||
-- (and so went on counting a reversed one) go.
|
||||
|
||||
@@ -72,7 +72,7 @@ pub const LEGACY_DB_FILE: &str = "wanderbooks.db";
|
||||
/// open (plan/served.md 3.9: before consent, the way back is always
|
||||
/// there), however far this version's projection has moved.
|
||||
/// SOURCE: plan/served.md 3.9, the lead's decision (2026-10-21: each
|
||||
/// schema in a file of its own); rules.md B-27.
|
||||
/// schema in a file of its own); BS-format-1.
|
||||
/// INVARIANTS:
|
||||
/// 1. A version opens or creates only its own schema's file (or the
|
||||
/// legacy file when that already holds its schema); a missing one is
|
||||
@@ -506,7 +506,7 @@ struct AttachRequest<'a> {
|
||||
description: Option<&'a str>,
|
||||
}
|
||||
|
||||
/// The evidence a bad-debt write-off files (plan P4b S7; rules.md B-41
|
||||
/// The evidence a bad-debt write-off files (plan P4b S7; BS-arap-5
|
||||
/// INVARIANT 1): the file that shows the debt is worthless — collection
|
||||
/// correspondence, a bankruptcy notice (Treas. Reg. §1.166-2). Given as
|
||||
/// bytes to file in the same call, or as an attachment already in the
|
||||
@@ -909,7 +909,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: books that tell every reader which format they are in.
|
||||
/// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate).
|
||||
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the format is newer than SUPPORTED_JOURNAL_FORMAT, or 0:
|
||||
/// SHOULD refuse (FormatRefused), journaling nothing
|
||||
@@ -969,7 +969,7 @@ impl Store {
|
||||
/// instead of misreading a line it thinks it knows, and books
|
||||
/// move past what their owner's older version reads only when
|
||||
/// the owner says so.
|
||||
/// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate), 3.9 and
|
||||
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate), 3.9 and
|
||||
/// D-39 (the format upgrade).
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the books declared it: SHOULD pass.
|
||||
@@ -1001,7 +1001,7 @@ impl Store {
|
||||
/// GOAL: older books move to this version's format at once, on the
|
||||
/// record, exactly once.
|
||||
/// SOURCE: plan/served.md 3.9 ("Format changes are the server's
|
||||
/// gate"); D-39; rules.md B-27.
|
||||
/// gate"); D-39; BS-format-1.
|
||||
/// INVARIANTS:
|
||||
/// 1. One journal line declares the whole format: the format moves
|
||||
/// exactly once, never feature by feature.
|
||||
@@ -1072,7 +1072,7 @@ impl Store {
|
||||
self.ensure_features(&needed)?;
|
||||
self.ensure_format()?;
|
||||
// invoicing.first_number is settable only while no numbered invoice
|
||||
// exists (A-2, rules.md B-40): the series has begun, and a number is
|
||||
// exists (A-2, BS-arap-4): the series has begun, and a number is
|
||||
// never reused or renumbered. Changing or clearing it is refused
|
||||
// before anything is journaled.
|
||||
if changes.iter().any(|c| c.key == "invoicing.first_number")
|
||||
@@ -1356,7 +1356,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: an account created with the line of the return it maps to.
|
||||
/// SOURCE: rules.md B-32 (policy.require_tax_category).
|
||||
/// SOURCE: BS-ledger-11 (policy.require_tax_category).
|
||||
/// INVARIANTS:
|
||||
/// 1. Rehearsed whole first: a refusal (of the account, or of its
|
||||
/// category) journals nothing.
|
||||
@@ -1512,7 +1512,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a draft that is finished and waiting on its receipt says so,
|
||||
/// durably, and replays the same.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-43; plan P4.
|
||||
/// SOURCE: BS-format-1, BS-entry-5; plan P4.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the engine refuses it (unknown or posted entry, a note the
|
||||
/// books won't keep): SHOULD refuse, journaling nothing.
|
||||
@@ -1543,7 +1543,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a draft that will never post can go, so it stops holding its
|
||||
/// period open, and the journal still says why.
|
||||
/// SOURCE: docs/spec/rules.md B-8, B-43; plan P4.
|
||||
/// SOURCE: BS-ledger-4, BS-entry-5; plan P4.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the entry is unknown or posted, or the reason is empty or
|
||||
/// breaks the books' text rule: SHOULD refuse, journaling
|
||||
@@ -1584,7 +1584,7 @@ impl Store {
|
||||
}
|
||||
|
||||
/// [`Self::post_entry`] behind the evidence gate (plan P4, I-5, D-47;
|
||||
/// rules.md B-43): refuses, journaling nothing, a draft that
|
||||
/// BS-entry-5): refuses, journaling nothing, a draft that
|
||||
/// [`ledger_core::evidence::requirement`] says needs evidence while it
|
||||
/// has no receipt filed on it or linked to it. This is the path the
|
||||
/// server posts a hand-made draft by; [`Self::post_entry`] stays the
|
||||
@@ -1594,7 +1594,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: no draft the receipt policy covers posts without the
|
||||
/// document that supports it, decided in one place.
|
||||
/// SOURCE: docs/spec/rules.md B-43; IRS Pub. 583.
|
||||
/// SOURCE: BS-entry-5; IRS Pub. 583.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the entry is covered and has no receipt: SHOULD refuse
|
||||
/// (ReceiptRequired), NEVER journal.
|
||||
@@ -1748,7 +1748,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a reversal never leaves a fixed asset's figures and its books
|
||||
/// apart.
|
||||
/// SOURCE: docs/spec/rules.md B-9, B-15; P3 depreciation review R3.
|
||||
/// SOURCE: BS-ledger-5, BS-asset-1; P3 depreciation review R3.
|
||||
/// SCENARIOS (the entry, or the original its reversal chain starts
|
||||
/// from, since reversing a reversal re-instates that original):
|
||||
/// 1. IF it is an asset's disposal entry:
|
||||
@@ -1774,7 +1774,7 @@ impl Store {
|
||||
/// 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.)
|
||||
/// version wrote replays as it was, BS-entry-4.)
|
||||
/// 6. Otherwise: a run of an active asset is un-posted (its month is
|
||||
/// due again, caught up by the next run).
|
||||
/// ```
|
||||
@@ -2142,10 +2142,10 @@ impl Store {
|
||||
/// depreciable_basis, built_in_gain_704c}`: the facts, and for the
|
||||
/// line's readers the figures as derived when written (null for a
|
||||
/// purchase's depreciable basis: the cost, whatever it becomes).
|
||||
/// Replay reads the facts and never recomputes the figures (rules.md
|
||||
/// B-28). It needs the journal feature `asset_basis`: refused,
|
||||
/// Replay reads the facts and never recomputes the figures (
|
||||
/// BS-entry-4). It needs the journal feature `asset_basis`: refused,
|
||||
/// journaling nothing, in books that haven't declared it (books an
|
||||
/// older version wrote, until their format upgrade: B-27).
|
||||
/// older version wrote, until their format upgrade: BS-format-1).
|
||||
pub fn set_asset_basis(
|
||||
&mut self,
|
||||
id: AssetId,
|
||||
@@ -2287,7 +2287,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: the books carry the schedule through the month's end.
|
||||
/// SOURCE: docs/spec/rules.md B-15; plan/served.md P3 "Settled in
|
||||
/// SOURCE: BS-asset-1; plan/served.md P3 "Settled in
|
||||
/// design" (2026-10-20): a month skipped is caught up in the
|
||||
/// month the run is made (an immaterial miss; a material one is
|
||||
/// restated, ASC 250, by a human and the CPA).
|
||||
@@ -2485,8 +2485,8 @@ impl Store {
|
||||
/// after its month, a run reversed and re-instated after the
|
||||
/// disposal's month) is that run's own error and correction, dated
|
||||
/// when they were made, the same with or without the disposal.
|
||||
/// SOURCE: docs/spec/rules.md B-15 (a disposed asset depreciates through
|
||||
/// its disposal day); B-9 (a mistake is corrected by an opposite
|
||||
/// SOURCE: BS-asset-1 (a disposed asset depreciates through
|
||||
/// its disposal day); BS-ledger-5 (a mistake is corrected by an opposite
|
||||
/// entry); plan/served.md P3, settled in design (a miss is
|
||||
/// corrected in the period the correction is made, a material
|
||||
/// one restated); Ledger::dispose_asset INVARIANT 1. P3 review
|
||||
@@ -2589,7 +2589,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a disposal takes exactly the depreciation of the days held,
|
||||
/// whatever the runs posted.
|
||||
/// SOURCE: docs/spec/rules.md B-15 (the disposal day is held);
|
||||
/// SOURCE: BS-asset-1 (the disposal day is held);
|
||||
/// Ledger::dispose_asset INVARIANTS 1, 2; P3 depreciation
|
||||
/// review R2.
|
||||
/// INVARIANTS:
|
||||
@@ -2986,7 +2986,7 @@ impl Store {
|
||||
self.rehearse(|l| l.close_period_to(id, to))?;
|
||||
if matches!(to, CloseTo::Members(_) | CloseTo::MembersCumulative { .. }) {
|
||||
// A close counted from its regime's start: an older version
|
||||
// would replay it under the run rule (format gate, B-27).
|
||||
// would replay it under the run rule (format gate, BS-format-1).
|
||||
// Refused before anything is journaled until the books
|
||||
// declare it.
|
||||
self.ensure_feature(crate::format::MEMBERS_CUMULATIVE)?;
|
||||
@@ -3145,7 +3145,7 @@ impl Store {
|
||||
/// then no-ops, which keeps replay deterministic: every account
|
||||
/// creation is an `account.added` event. The engine's account
|
||||
/// (`Ledger::add_control_account`): never refused for its name or a
|
||||
/// missing tax category (rules.md B-32), so an invoice, a bill or a
|
||||
/// missing tax category (BS-ledger-11), so an invoice, a bill or a
|
||||
/// payroll run is never refused over a chart label.
|
||||
fn ensure_control_account(
|
||||
&mut self,
|
||||
@@ -3234,7 +3234,7 @@ impl Store {
|
||||
Ok((entry_id, journaled))
|
||||
}
|
||||
|
||||
/// The feature a document's lines need (rules.md B-27): a line naming
|
||||
/// The feature a document's lines need (BS-format-1): a line naming
|
||||
/// a project is `document_line_projects`'s; a document naming none is
|
||||
/// written as every version before it wrote one.
|
||||
fn ensure_document_lines(&self, lines: &[DocumentLine]) -> Result<(), StoreError> {
|
||||
@@ -3244,7 +3244,7 @@ impl Store {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The feature a document's new fields need (rules.md B-27): an
|
||||
/// The feature a document's new fields need (BS-format-1): an
|
||||
/// invoice or bill naming a number, terms, a snapshot, a reference, a
|
||||
/// memo or a duplicate's reason, or a line naming its account, quantity
|
||||
/// or unit price, needs `documents_v2` (plan P4b S4.3; D-52). A
|
||||
@@ -3319,7 +3319,7 @@ impl Store {
|
||||
/// GOAL: a document's new fields are journaled with it, so replay can
|
||||
/// never lose them, and a document naming none is written byte
|
||||
/// for byte as an earlier version wrote it.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-40 (plan P4b S4.3); A-2, A-13.
|
||||
/// SOURCE: BS-format-1, BS-arap-4 (plan P4b S4.3); A-2, A-13.
|
||||
/// INVARIANTS:
|
||||
/// 1. A write naming a number, terms, a snapshot, a reference, a memo,
|
||||
/// a line account, quantity or unit price MUST need journal feature
|
||||
@@ -3446,7 +3446,7 @@ impl Store {
|
||||
}
|
||||
|
||||
/// The issued copy of an invoice, filed in the call that issues it
|
||||
/// (plan P4b S4.3 item 11, A-7; rules.md B-40 item 3): the entry, then
|
||||
/// (plan P4b S4.3 item 11, A-7; BS-arap-4 item 3): the entry, then
|
||||
/// `invoice.created`, then `receipt.attached` on the entry
|
||||
/// (`INV-0007.pdf`, `application/pdf`, "Issued invoice"), then
|
||||
/// `attachment.linked` to the invoice. The server renders the PDF
|
||||
@@ -3462,7 +3462,7 @@ impl Store {
|
||||
/// GOAL: the copy sent is kept with the invoice, or nothing is.
|
||||
/// SOURCE: IRS Pub. 583 (keep invoices); Rev. Proc. 98-25 (the audit
|
||||
/// trail keeps the record as issued); plan P4b S4.3, 8.3.11;
|
||||
/// rules.md B-40 item 3.
|
||||
/// BS-arap-4 item 3.
|
||||
/// INVARIANTS:
|
||||
/// 1. Every refusal (an unknown customer, an invalid line or due
|
||||
/// date, a duplicate number, a closed period, a feature the books
|
||||
@@ -3811,7 +3811,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a payment is journaled once and replays to the same figures,
|
||||
/// in any version that can open the books.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-38; plan/served.md P4b.7
|
||||
/// SOURCE: BS-format-1, BS-arap-2; plan/served.md P4b.7
|
||||
/// (document_standing).
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the engine refuses it (overpaid, before the invoice, a
|
||||
@@ -3908,7 +3908,7 @@ impl Store {
|
||||
}
|
||||
|
||||
/// Settle one or more invoices or bills in one entry (plan P4b S6;
|
||||
/// rules.md B-42): the core posts it ([`ledger_core::Ledger::settle`]);
|
||||
/// BS-arap-6): the core posts it ([`ledger_core::Ledger::settle`]);
|
||||
/// this journals its lines once and one `invoice.payment_received` or
|
||||
/// `bill.paid` per application, each naming the control line it tags,
|
||||
/// then the payment method. A single legacy-shaped payment is
|
||||
@@ -4026,7 +4026,7 @@ impl Store {
|
||||
Ok(live)
|
||||
}
|
||||
|
||||
/// Write off an invoice as a bad debt (plan P4b S7; rules.md B-41),
|
||||
/// Write off an invoice as a bad debt (plan P4b S7; BS-arap-5),
|
||||
/// filing its evidence in the same call. The write-off's entry (Dr
|
||||
/// 6990 Bad Debt Expense / Cr A/R) is journaled through the standard
|
||||
/// entry flow, then `invoice.written_off`, then the evidence: a
|
||||
@@ -4038,7 +4038,7 @@ impl Store {
|
||||
/// GOAL: a bad debt comes off the receivables with the proof it was
|
||||
/// worthless, in one call that is all or nothing.
|
||||
/// SOURCE: IRC §166(a); Treas. Reg. §1.166-1(e), -2(a), -3(a);
|
||||
/// docs/spec/rules.md B-41; plan P4b S7, 8.3.6.
|
||||
/// BS-arap-5; plan P4b S7, 8.3.6.
|
||||
/// INVARIANTS:
|
||||
/// 1. A write that needs journal feature documents_v2 (the event
|
||||
/// type) MUST be refused in books that haven't declared it,
|
||||
@@ -4144,7 +4144,7 @@ impl Store {
|
||||
}
|
||||
Ok((entry_id, attachment_id))
|
||||
}
|
||||
/// The journal features a settlement needs (rules.md B-27, B-42):
|
||||
/// The journal features a settlement needs (BS-format-1, BS-arap-6):
|
||||
/// `documents_v2` for more than one application, a discount or a fee
|
||||
/// (an older version would drop them, and the balance would be wrong),
|
||||
/// `document_standing` when an application pays more than an older
|
||||
@@ -4207,7 +4207,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a send is journaled once and replays to the same record, in
|
||||
/// every version that can read the books.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-38; plan P4b S5, A-4.
|
||||
/// SOURCE: BS-format-1, BS-arap-2; plan P4b S5, A-4.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the engine refuses it (unknown or void invoice, a date
|
||||
/// before the invoice, no recipients, a text the books won't
|
||||
@@ -4528,13 +4528,13 @@ impl Store {
|
||||
Ok(live)
|
||||
}
|
||||
|
||||
/// Add a project (rules.md B-37): `class.added`, then `project.set`
|
||||
/// Add a project (BS-statement-5): `class.added`, then `project.set`
|
||||
/// when `facts` say more than the defaults. Returns its id.
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: a project in one command, journaled as two events only when
|
||||
/// it has facts, so a name-only project is a plain class.
|
||||
/// SOURCE: docs/spec/rules.md B-37 item 1; B-27 (journal feature
|
||||
/// SOURCE: BS-statement-5 item 1; BS-format-1 (journal feature
|
||||
/// `projects`).
|
||||
/// INVARIANTS:
|
||||
/// 1. A refusal journals nothing: the whole record is rehearsed, and
|
||||
@@ -5186,7 +5186,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: rename an account, keeping the name it had in the journal.
|
||||
/// SOURCE: rules.md B-31; Rev. Proc. 98-25 (docs/spec/sources/
|
||||
/// SOURCE: BS-ledger-10; Rev. Proc. 98-25 (docs/spec/sources/
|
||||
/// irs-records.md): a report printed under the old name can
|
||||
/// be tied to the new one.
|
||||
/// INVARIANTS:
|
||||
@@ -5251,7 +5251,7 @@ impl Store {
|
||||
/// Set (or clear) an account's tax category and deductible percent.
|
||||
/// Journaled as `account.tax_set`. Under
|
||||
/// `policy.require_tax_category = refuse`, an account that needs a
|
||||
/// category is never left without one (rules.md B-32;
|
||||
/// category is never left without one (BS-ledger-11;
|
||||
/// `Ledger::check_tax_category_kept`).
|
||||
pub fn set_account_tax(
|
||||
&mut self,
|
||||
@@ -5646,7 +5646,7 @@ impl Store {
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
/// The journal feature a link to `subject` needs, if any: a subject
|
||||
/// kind an older version doesn't know (a project, rules.md B-37).
|
||||
/// kind an older version doesn't know (a project, BS-statement-5).
|
||||
/// Callers filing a file with links ask it before filing, so a refusal
|
||||
/// leaves nothing half-filed.
|
||||
pub fn subject_feature(subject: Subject) -> Option<&'static str> {
|
||||
@@ -6847,8 +6847,8 @@ fn document_line_json(l: &DocumentLine) -> Value {
|
||||
"description": l.description,
|
||||
"amount": l.amount.to_string(),
|
||||
});
|
||||
// Its project, behind the feature document_line_projects (rules.md
|
||||
// B-27, B-37 item 8); a line naming none is written as before it.
|
||||
// Its project, behind the feature document_line_projects (
|
||||
// BS-format-1, BS-statement-5 item 8); a line naming none is written as before it.
|
||||
if let Some(c) = l.class_id {
|
||||
v["class_id"] = json!(c);
|
||||
}
|
||||
@@ -6927,7 +6927,7 @@ fn invoice_fields_json(payload: &mut Value, fields: &arap::InvoiceFields) {
|
||||
}
|
||||
|
||||
/// Add a bill's new fields to its `bill.created` payload, each key only when
|
||||
/// set. A duplicate's reason is journaled for the record (rules.md B-40 item
|
||||
/// set. A duplicate's reason is journaled for the record (BS-arap-4 item
|
||||
/// 4); the bill itself keeps none.
|
||||
fn bill_fields_json(payload: &mut Value, fields: &arap::BillFields) {
|
||||
if let Some(r) = &fields.vendor_ref {
|
||||
@@ -7151,7 +7151,7 @@ fn parse_side(s: &str) -> Result<Side, StoreError> {
|
||||
/// earlier version accepted ("+10000-01-01" and "-0001-01-01" included).
|
||||
/// The calendar the books keep (ledger_core::calendar) bounds new
|
||||
/// commands, never replay: a date an earlier version journaled always
|
||||
/// replays (rules.md B-28).
|
||||
/// replays (BS-entry-4).
|
||||
fn parse_date(s: &str) -> Result<chrono::NaiveDate, StoreError> {
|
||||
chrono::NaiveDate::parse_from_str(s, "%Y-%m-%d")
|
||||
.map_err(|_| StoreError::JournalCorrupt(format!("bad date {s}")))
|
||||
@@ -7248,7 +7248,7 @@ fn get_opt_decimal(p: &Value, key: &str) -> Result<Decimal, StoreError> {
|
||||
/// A full TIN is found as the version before P3 found one
|
||||
/// (`ledger_core::parties::replaying`): a name, reason or fact an earlier
|
||||
/// version took replays, however the commands' detector has widened since
|
||||
/// (rules.md B-28).
|
||||
/// (BS-entry-4).
|
||||
pub(crate) fn replay_line_into_ledger(
|
||||
ledger: &mut Ledger,
|
||||
line: &JournalLine,
|
||||
@@ -7384,7 +7384,7 @@ fn replay_line(
|
||||
let want = get_u64(p, "id")?;
|
||||
let orig = get_u64(p, "reverses")?;
|
||||
// As journaled: a reversal later rules would refuse (a void
|
||||
// under a payment that stands) replays (rules.md B-28).
|
||||
// under a payment that stands) replays (BS-entry-4).
|
||||
let got = ledger.replay_reverse_entry(
|
||||
orig,
|
||||
parse_date(get_str(p, "date")?)?,
|
||||
@@ -7400,7 +7400,7 @@ fn replay_line(
|
||||
let want = get_u64(p, "id")?;
|
||||
// No convention (every schedule before P3): equal months, as
|
||||
// they were posted. A convention this version doesn't know is
|
||||
// newer, never corrupt (rules.md B-27).
|
||||
// newer, never corrupt (BS-format-1).
|
||||
let convention = match p.get("convention") {
|
||||
None | Some(Value::Null) => ledger_core::ScheduleConvention::MonthlyEven,
|
||||
Some(Value::String(c)) => {
|
||||
@@ -7525,7 +7525,7 @@ fn replay_line(
|
||||
}
|
||||
"account.renamed" => {
|
||||
// Only that the account exists: the name rules are the
|
||||
// command's (rules.md B-28). `code`, `previous` and `reason`
|
||||
// command's (BS-entry-4). `code`, `previous` and `reason`
|
||||
// are the record, not state.
|
||||
ledger.replay_rename_account(get_u64(p, "account_id")?, get_str(p, "name")?)?;
|
||||
}
|
||||
@@ -7567,7 +7567,7 @@ fn replay_line(
|
||||
| "attachment.text_extracted" => {
|
||||
// Not accounting state; the projection records them. (The text
|
||||
// record is checked for shape here: an unknown status is newer,
|
||||
// rules.md B-27.)
|
||||
// BS-format-1.)
|
||||
if line.line_type == "attachment.text_extracted" {
|
||||
crate::meta::text_extracted_of(line)?;
|
||||
}
|
||||
@@ -7578,7 +7578,7 @@ fn replay_line(
|
||||
}
|
||||
"audit.run" => {
|
||||
// Not accounting state; the projection records it. Checked
|
||||
// for shape here (an unknown scope is newer, rules.md B-27).
|
||||
// for shape here (an unknown scope is newer, BS-format-1).
|
||||
crate::meta::audit_run_of(line)?;
|
||||
}
|
||||
// A claim that someone checked; no figure moves.
|
||||
@@ -7647,7 +7647,7 @@ fn replay_line(
|
||||
}
|
||||
"party.updated" => {
|
||||
// A field this version doesn't know: a newer one wrote it
|
||||
// (rules.md B-27). A known field with a bad value is damage.
|
||||
// (BS-format-1). A known field with a bad value is damage.
|
||||
if let Some(field) = p
|
||||
.get("change")
|
||||
.and_then(|c| c.get("field"))
|
||||
@@ -7754,7 +7754,7 @@ fn replay_line(
|
||||
// this line says it was the asset's run for the month, which is
|
||||
// what the books carry for the asset (Ledger::accumulated_posted).
|
||||
// Replay checks only that it is well formed and names an asset
|
||||
// and entry that exist (rules.md B-28).
|
||||
// and entry that exist (BS-entry-4).
|
||||
let amount = get_str(p, "amount")?.parse::<Decimal>().map_err(|_| {
|
||||
StoreError::JournalCorrupt("asset.depreciation_posted amount".into())
|
||||
})?;
|
||||
@@ -8083,8 +8083,8 @@ fn optional_decimal(p: &Value, key: &str) -> Result<Option<Decimal>, ()> {
|
||||
|
||||
/// An `asset.basis_set`'s facts. A rule or §704(c) method this version
|
||||
/// doesn't know was written by a newer one: NewerJournal, never corrupt
|
||||
/// (rules.md B-27). The figures the line carries are type-checked and
|
||||
/// otherwise left to its readers: replay never recomputes them (B-28).
|
||||
/// (BS-format-1). The figures the line carries are type-checked and
|
||||
/// otherwise left to its readers: replay never recomputes them (BS-entry-4).
|
||||
fn asset_basis_from_journal(
|
||||
line: &JournalLine,
|
||||
p: &Value,
|
||||
@@ -8122,7 +8122,7 @@ fn asset_basis_from_journal(
|
||||
|
||||
/// A journaled close's target. A rounding rule only a newer version
|
||||
/// writes (an unknown name, or a value that isn't a name) is newer, never
|
||||
/// corrupt (rules.md B-27).
|
||||
/// corrupt (BS-format-1).
|
||||
fn close_to_from_journal(line: &JournalLine, v: Option<&Value>) -> Result<CloseTo, StoreError> {
|
||||
let corrupt = |what: &str| StoreError::JournalCorrupt(format!("close_to: {what}"));
|
||||
let ids = |v: &Value| -> Result<Vec<AccountId>, StoreError> {
|
||||
@@ -9002,11 +9002,11 @@ fn apply_line_rows(conn: &Connection, line: &JournalLine) -> Result<(), StoreErr
|
||||
)?;
|
||||
}
|
||||
// A payment moves no document row: what a document is paid is read
|
||||
// from the ledger lines tagged with it (schema v15, rules.md B-38).
|
||||
// from the ledger lines tagged with it (schema v15, BS-arap-2).
|
||||
"invoice.payment_received" => {}
|
||||
// A write-off moves no document row either: written_off and the
|
||||
// status are derived from the tagged lines (the tag is set by
|
||||
// replay; rules.md B-41).
|
||||
// replay; BS-arap-5).
|
||||
"invoice.written_off" => {}
|
||||
"bill.paid" => {
|
||||
conn.execute(
|
||||
@@ -9396,8 +9396,8 @@ pub enum Subject {
|
||||
Schedule(u64),
|
||||
/// A reconciliation (its statement).
|
||||
Reconciliation(u64),
|
||||
/// A project (its contract, spec, pitch, correspondence; rules.md
|
||||
/// B-37). Journal feature `projects`.
|
||||
/// A project (its contract, spec, pitch, correspondence;
|
||||
/// BS-statement-5). Journal feature `projects`.
|
||||
Project(u64),
|
||||
/// The company itself (formation documents).
|
||||
Company,
|
||||
|
||||
Reference in new issue
Block a user