Skip to content

calternal_money::edit

The file edits the Money API offers (#462): new budget files, accounts, categories, assignments and simple transactions.

Every edit is a pure function from a Document to new text. The rules:

  • Change only the lines the edit owns. Every other byte, including unknown Markdown, frontmatter and line endings, stays as it was (#404).
  • New lines use the file’s existing line ending.
  • The caller re-projects the result (crate::ledger::project) before it writes, so an edit can never store a file the reader rejects.
  • IDs are caller-supplied or derived by unique_id; this crate has no randomness or clock.

Splits, general transfers and FX rows have no amount editor in this build: the plugin refuses those edits (ErrorKind::Unsupported). Per-Account cleared marks use inert properties without changing postings (#1130).

Source: crates/calternal-money/src/edit.rs

pub fn add_account(
document: &Document,
id: &str,
name: &str,
kind: AccountKind,
currency: &str,
payment_category: Option<&Reference>,
) -> Result<String>

Append an account section to Accounts.md. A Card account links its payment Category, which the caller creates in Budget.md first.

Source: crates/calternal-money/src/edit.rs:222

pub fn add_category(
document: &Document,
group: &str,
id: &str,
name: &str,
kind: &str,
) -> Result<String>

Add a category under the ## group named group, creating the group before the marker and subscription sections when it does not exist.

Source: crates/calternal-money/src/edit.rs:272

pub fn add_transaction(document: &Document, row: &TransactionRow) -> Result<String>

Append a transaction row at the end of a month file.

Source: crates/calternal-money/src/edit.rs:404

pub fn append_raw_lines(document: &Document, raw_lines: &[String]) -> String

Append raw lines moved from another month file (a date change across months). Each moved line gets this file’s line ending.

Source: crates/calternal-money/src/edit.rs:517

pub fn block_ids(document: &Document) -> HashSet<String>

Every block ID in a document (for uniqueness checks before an insert).

Source: crates/calternal-money/src/edit.rs:74

pub fn new_accounts_file(budget_id: &str, currency: &str) -> Result<String>

Accounts.md for a new budget: frontmatter and title, no accounts.

Source: crates/calternal-money/src/edit.rs:123

pub fn new_budget_file(budget_id: &str, title: &str, currency: &str) -> Result<String>

Budget.md for a new budget: frontmatter, the title and the system categories. No sample categories or amounts (the No fake data rule).

Source: crates/calternal-money/src/edit.rs:107

pub fn new_month_file(budget_id: &str, month: &str) -> Result<String>

A new month file with its frontmatter and an empty Transactions section.

Source: crates/calternal-money/src/edit.rs:134

pub fn remove_transaction(document: &Document, id: &str) -> Result<(String, Vec<String>)>

Remove one transaction and its indented children. Return the new text and removed lines so a cross-month move keeps metadata and attachments (#462).

Source: crates/calternal-money/src/edit.rs:505

pub fn replace_transaction(document: &Document, row: &TransactionRow) -> Result<String>

Rewrite one transaction row; its child lines (notes, attachments) stay.

Source: crates/calternal-money/src/edit.rs:445

pub fn set_assigned(
document: &Document,
category_id: &str,
month: &str,
amount: Minor,
currency: &str,
) -> Result<String>

Set the total assigned to category_id in month to amount.

With no row, a new - assigned, month, amount CUR ^id row is added under the category (none for zero). With rows, the first row absorbs the difference so the rows sum to amount; a single row that becomes zero is removed. Invariant: after the edit, the month’s assigned rows for the category sum exactly to amount.

Source: crates/calternal-money/src/edit.rs:343

pub fn set_transaction_property(
document: &Document,
id: &str,
key: &str,
value: &str,
) -> Result<String>

Set one non-posting child field, preserving every other source byte. The field value is one line; callers JSON-encode multiline notes (#1130).

Source: crates/calternal-money/src/edit.rs:452

pub fn simple_row(
id: &str,
date: &str,
amount_text: String,
currency: &str,
account: Reference,
category: Reference,
payee: &str,
) -> TransactionRow

Build a simple row from its parts (the API’s create and edit shape).

Source: crates/calternal-money/src/edit.rs:556

pub fn slug(name: &str) -> String

A lowercase slug made of [a-z0-9-] from a display name (may be empty).

Source: crates/calternal-money/src/edit.rs:37

pub fn unique_id(base: &str, prefix: &str, taken: &HashSet<String>) -> String

A stable ID from base that is not in taken: base, base-2, … Falls back to prefix when the slug is empty (a name with no ASCII).

Source: crates/calternal-money/src/edit.rs:58

pub fn with_cleared(payee: &str, cleared: bool) -> String

Add or remove the #cleared tag in a payee and memo.

Source: crates/calternal-money/src/edit.rs:526

pub const CARD_PAYMENTS_GROUP: &str

The group that holds card payment Categories (“Credit Card Payments”; DESIGN §48; #916).

Source: crates/calternal-money/src/edit.rs:34

pub const SYSTEM_CATEGORY_IDS: [&str; 4]

The marker and system categories every new budget starts with. They hold no money of their own: Income and Opening balances feed Ready to Assign; Split and Transfer mark rows with child legs.

Source: crates/calternal-money/src/edit.rs:30