Functional Weave
Code in Python

charity.restricted-funds@1.0.0

README.md

2,104 bytes · view raw

# charity.restricted-funds

Charge a list of spending to a charity's funds under the basic rule of fund
accounting: money given for a particular purpose (a restricted fund) may only
be spent on that purpose, and general spending comes out of unrestricted
funds.

For each spend, in the order given:

1. a spend with a `purpose` is charged to the restricted funds for that
   purpose, in the order the funds are listed, as far as their balances go;
2. whatever is left, and every spend without a purpose, is charged to the
   unrestricted funds, in the order listed;
3. if that still does not cover it, the whole allocation is refused with
   `insufficient funds for spend "<id>": short by <minor units>`.

So a restricted fund is never overdrawn and never used for anything else,
even when it holds money that would cover a general bill. The result lists
every draw (spend, fund, amount) in the order made, and every fund with its
closing balance in the order given.

## Decisions

- **Refuse rather than record a deficit.** A restricted fund in deficit is a
  real finding in charity accounts (it usually means unrestricted money has
  to make it good), so a deficit is never created silently: the caller sees
  the shortfall and decides.
- **Order is the caller's.** Which restricted fund is used first when several
  share a purpose, and which unrestricted fund pays first, follow the lists
  as given, so the answer is deterministic and the policy stays visible.
- An unrestricted fund may not carry a purpose. Designated funds (unrestricted
  money the trustees have set aside) are a management choice, not a legal
  restriction; model them as their own restricted-like purpose only if your
  policy treats them that way.
- Amounts are integer minor units, all in one currency.

## Background

The Charities SORP (FRS 102) requires restricted and unrestricted funds to be
accounted for separately, and spending on a restricted purpose to be charged
to the restricted fund. This capability applies that rule mechanically; it
does not decide whether an item of spending falls within a fund's purpose.