feat: entity-aware owner equity — chart templates, draws, distributions, dividends
Every business has owners, and how owners put money in and take it out
depends on what the business is. wanderbooks now knows the four common
US shapes:
- books.chart_template {entity_type, owners}: a starter chart for a sole
proprietorship (owner's capital and draws), partnership or
multi-member LLC (capital and distributions per partner, guaranteed
payments), S corporation (stock, APIC, shareholder distributions,
officer compensation, retained earnings) or C corporation (dividends,
income tax expense), plus common income and expense accounts with
tax categories, and the wanderbooks.toml settings that go with it
(tax form, members with equal-share placeholders that sum to exactly
100, close target). A proposal for the agent to review with the human.
- Closing: CloseTo is now RetainedEarnings { sweep }, Account { into,
sweep } (a sole proprietor's capital) or Members([MemberClose { capital,
share, distributions }]). Sweeps zero owner-pay equity accounts into
their target at close: draws into owner's capital, dividends or
distributions into retained earnings, each partner's distributions
into their own capital. Validation (equity, distinct, shares sum to 1)
runs in the pre-close preview, before anything is journaled. The
journal records the target; journals with no target or the old
"retained_earnings" string still replay.
- Members' equity: a partner's distributions account is part of their
capital; its activity reports as distributions.
- Config: members' distribution_account; [books] close_into and
close_sweep for single-owner businesses (rejected alongside members).
The cash flow names members on their distribution accounts too.
Tests: a sole proprietor (net 2,000 and 500 of draws into capital: 6,500,
the cash); a corporation (dividends 300 into retained earnings: 600); a
partnership with distribution accounts (Bob 100 + 25 - 20 = 105, swept at
close, February begins there); bad sweep accounts; templates round-trip
through the chart parser, unique codes, equity per entity, every tax
category valid for the entity's return; stdio: template -> settings ->
import -> postings -> close with the exact closing lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MtYEaR6M6Ybdhm6X98BWNu
This commit is contained in:
17 files changed
+1277
-173
No files matched your search
@@ -671,6 +671,10 @@ pub struct MemberCapital {
|
||||
/// Their capital account (equity): contributions credit it,
|
||||
/// distributions debit it.
|
||||
pub capital_account: crate::AccountId,
|
||||
/// Their distributions account (contra-equity), if distributions are
|
||||
/// recorded there rather than directly against capital. Part of their
|
||||
/// capital on every statement; zeroed into capital at close.
|
||||
pub distribution_account: Option<crate::AccountId>,
|
||||
/// Share of income, e.g. 0.5. The shares must sum to exactly 1.
|
||||
pub share: Decimal,
|
||||
}
|
||||
@@ -738,15 +742,17 @@ pub fn members_equity(
|
||||
}
|
||||
let mut seen = BTreeSet::new();
|
||||
for m in members {
|
||||
let account = ledger
|
||||
.chart()
|
||||
.get(m.capital_account)
|
||||
.ok_or(LedgerError::UnknownAccount(m.capital_account))?;
|
||||
if account.account_type != AccountType::Equity || !seen.insert(m.capital_account) {
|
||||
return Err(LedgerError::InvalidMembers(format!(
|
||||
"{}: capital account {} must be a distinct equity account",
|
||||
m.name, account.code
|
||||
)));
|
||||
for id in std::iter::once(m.capital_account).chain(m.distribution_account) {
|
||||
let account = ledger
|
||||
.chart()
|
||||
.get(id)
|
||||
.ok_or(LedgerError::UnknownAccount(id))?;
|
||||
if account.account_type != AccountType::Equity || !seen.insert(id) {
|
||||
return Err(LedgerError::InvalidMembers(format!(
|
||||
"{}: account {} must be a distinct equity account",
|
||||
m.name, account.code
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
let day_before = start.pred_opt().ok_or(LedgerError::InvalidDateRange {
|
||||
@@ -788,11 +794,28 @@ pub fn members_equity(
|
||||
}
|
||||
(credits, debits)
|
||||
};
|
||||
// A member's capital is their capital account plus their distributions
|
||||
// account (a debit balance, so it reduces capital).
|
||||
let capital: Vec<Decimal> = members
|
||||
.iter()
|
||||
.map(|m| capital_before(m.capital_account))
|
||||
.map(|m| {
|
||||
capital_before(m.capital_account)
|
||||
+ m.distribution_account.map_or(Decimal::ZERO, capital_before)
|
||||
})
|
||||
.collect();
|
||||
// (contributions, distributions): credits to capital are
|
||||
// contributions; debits to capital and net debits to the distributions
|
||||
// account are distributions.
|
||||
let flow: Vec<(Decimal, Decimal)> = members
|
||||
.iter()
|
||||
.map(|m| {
|
||||
let (credits, debits) = flows(m.capital_account);
|
||||
let (dc, dd) = m
|
||||
.distribution_account
|
||||
.map_or((Decimal::ZERO, Decimal::ZERO), flows);
|
||||
(credits, debits + dd - dc)
|
||||
})
|
||||
.collect();
|
||||
let flow: Vec<(Decimal, Decimal)> = members.iter().map(|m| flows(m.capital_account)).collect();
|
||||
|
||||
// Everything in equity that isn't a capital account is partnership
|
||||
// earnings not yet distributed: allocate it by share.
|
||||
|
||||
Reference in new issue
Block a user