Add the section on kroner balances and the bank

This commit is contained in:
ai-bot committed 2026-11-15 13:36:37 +00:00
1 parent 2314899f10
commit 293be22118
1 file changed
+38
+38
View File
@@ -189,6 +189,44 @@ default**. See open question Q2.
--- ---
### 3.11 Kroner on an account, and the bank
A market can hold kroner as well as sats. The kroner balance of an account is **derived and never
stored**: the kroner that came in minus the kroner that went out, over that account's own
transactions, as of a date.
- A leg carries one currency (§4), so the kroner of an account are exactly `leg_in_ore` (in) and
`leg_out_ore` (out) of its transactions. `value_ore` is not a balance movement — it is the NOK
value of a BTC leg — and `fee_ore` is always 0 (§3.2), so neither enters the balance.
- A `trade` buy therefore lowers the balance by the kroner paid and a `trade` sell raises it by
the kroner received. `income`, `spend`, `gift_received` and `gift_given` do not move it.
- Nothing new is stored for this: it is a sum over rows that already exist.
**The bank.** One account is the bank: the row `Bank` in `markets`, `kind = 'other'`,
`taxable = 0`, `archived = 1`, seeded on first run like the rates and named by the setting
`bank_market_id`. It is the counterparty for the costs of §3.10 and it can never go negative,
because the cost row carries both its kroner legs.
- The bank is left out of the account pickers, out of the account admin, out of the main sheet
and out of the report's account rows, since it holds no sats and is nobody's holding. Its name
is shown in the transaction list, where a cost reads `Bank` in the `Konto` column.
- No other transaction may name the bank.
Kroner and sats move between the real accounts with a `transfer_out`, which carries **either sats
or kroner, never both**:
- `transfer_out` with `leg_out_sats`: exactly as today (§3.3), and `Til` is required.
- `transfer_out` with `leg_out_ore`: the kroner leave the source account and arrive on the
destination account, whose generated `transfer_in` gets `leg_in_ore` equal to the sent amount.
No lot is involved and nothing is realized: kroner are kroner.
- **An empty `Til` is a withdrawal, and it is kroner only.** The kroner leave the ledger and no
`transfer_in` is generated. A `transfer_out` of sats always needs a `Til`.
A `transfer_out` is refused when the source account does not hold enough of the currency as of
the transaction date: the lot ledger refuses sats and names the shortfall in sats (§5.2), and the
derived balance refuses kroner and names the shortfall in kroner. Skuld never invents coins or
kroner. A buy that overdraws the kroner balance is not refused; it is shown as a negative balance.
## 4. Data model ## 4. Data model
SQLite, one file, on the `main` volume. Schema lives in `database.py` as one versioned SQLite, one file, on the `main` volume. Schema lives in `database.py` as one versioned