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
Functions
Section titled “Functions”add_account
Section titled “add_account”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
add_category
Section titled “add_category”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
add_transaction
Section titled “add_transaction”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
append_raw_lines
Section titled “append_raw_lines”pub fn append_raw_lines(document: &Document, raw_lines: &[String]) -> StringAppend 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
block_ids
Section titled “block_ids”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
new_accounts_file
Section titled “new_accounts_file”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
new_budget_file
Section titled “new_budget_file”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
new_month_file
Section titled “new_month_file”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
remove_transaction
Section titled “remove_transaction”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
replace_transaction
Section titled “replace_transaction”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
set_assigned
Section titled “set_assigned”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
set_transaction_property
Section titled “set_transaction_property”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
simple_row
Section titled “simple_row”pub fn simple_row( id: &str, date: &str, amount_text: String, currency: &str, account: Reference, category: Reference, payee: &str,) -> TransactionRowBuild 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) -> StringA lowercase slug made of [a-z0-9-] from a display name (may be empty).
Source: crates/calternal-money/src/edit.rs:37
unique_id
Section titled “unique_id”pub fn unique_id(base: &str, prefix: &str, taken: &HashSet<String>) -> StringA 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
with_cleared
Section titled “with_cleared”pub fn with_cleared(payee: &str, cleared: bool) -> StringAdd or remove the #cleared tag in a payee and memo.
Source: crates/calternal-money/src/edit.rs:526
Constants
Section titled “Constants”CARD_PAYMENTS_GROUP
Section titled “CARD_PAYMENTS_GROUP”pub const CARD_PAYMENTS_GROUP: &strThe group that holds card payment Categories (“Credit Card Payments”; DESIGN §48; #916).
Source: crates/calternal-money/src/edit.rs:34
SYSTEM_CATEGORY_IDS
Section titled “SYSTEM_CATEGORY_IDS”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.