Refuse an over-drawn real account and exempt the bank

This commit is contained in:
ai-bot committed 2026-11-16 19:32:55 +00:00
1 parent d1b6f26222
commit 9aa70eb717
1 file changed
+14 -5
+14 -5
View File
@@ -393,18 +393,27 @@ def _picks(conn, tx_id):
return [dict(row) for row in rows]
def _move_kroner(balances, tx):
"""Track the derived kroner balance and refuse an over-drawn transfer.
def _bank_market_id(conn):
"""The account that pays the costs (docs/spec.md section 3.11)."""
row = conn.execute(
"SELECT value FROM settings WHERE key = 'bank_market_id'"
).fetchone()
return int(row["value"]) if row else None
Kroner are never stored, so the balance is carried along the replay. Only a
transfer is refused: a buy that overdraws is allowed (section 3.11).
def _move_kroner(balances, tx, bank_id):
"""Track the derived kroner balance and refuse an over-drawn account.
Kroner are never stored, so the balance is carried along the replay. No real
account may go negative; the bank may, and its negative balance is how much
has been drawn from it (docs/spec.md section 3.11).
"""
market_id = tx["market_id"]
if market_id is None:
return
balance = balances.get(market_id, 0)
out_ore = tx["leg_out_ore"] or 0
if out_ore and tx["type"] == "transfer_out" and balance < out_ore:
if out_ore and balance < out_ore and market_id != bank_id:
raise LedgerError(
"Kontoen har ikkje nok kroner: det manglar %s kr."
% rates.kroner_whole(out_ore - balance)