Finance journals
The journal outbox. Each Finance module proposes a balanced journal for every accounting effect, validated against your reference data, numbered without gaps and ready for your accounting system. List, inspect, retry, void and reverse them.
Petawork Finance is not a ledger. Your accounting system keeps the books. When something in Finance has an accounting effect (a bill is approved, a payment goes out, an invoice is issued, cash is applied, a balance is written off, a reconciliation finds an adjustment), the module that did it proposes a journal: balanced lines for your accounting system. The journals wait in an outbox until a connector exports them.
Nobody types a journal in Finance. You list them, open one to see its lines and where it came from, and act on it in
four ways: retry, void, reverse, or leave it for the connector. Open the outbox in Finance > Journals
(/finance/journals). It lists the newest first. You can filter by status, entity and posting month, and the filters
are in the page's address, so a link keeps them. Pick a journal to open it beside the list.
What a journal holds
| Field | What it is |
|---|---|
| Number | JNL-000001 and up, per entity, with no gaps. Given when the journal first becomes ready |
| Status | draft, ready, posted, failed or void (below) |
| Entity | The entity the journal belongs to. Its functional currency is the journal's |
| Date and period | The source's date, and the month the journal posts in, which is that date's month or the next open one (periods) |
| Source | The module, the kind of record (a bill, a payment) and its id |
| Memo | A line of text from the module |
| Lines | Each line names an account (the entity's or a shared one) and a debit or a credit in minor units, with its currency, the exchange rate, the amount in the functional currency, and optionally a tax code, a vendor or customer, and dimensions |
| Problems | Why a draft is not ready yet, in words |
| Reversal links | On a reversal, the journal it reverses. On the original, its reversal |
| Export | The id in the accounting system once posted, or the error when an export failed |
Amounts are whole numbers of the currency's minor units (cents, yen). Finance never stores or adds money as a fraction.
Statuses
| Status | Meaning | Number |
|---|---|---|
draft |
Something blocks it: a missing exchange rate, an inactive account, dimension value or tax code, or a blocked vendor. Its problems say what. Fix the reference data, then Retry | None yet |
ready |
Balanced, checked and waiting for the connector | Given |
posted |
Exported to the accounting system, with its id there | Kept |
failed |
The export failed. The error says why. Retry makes it ready again | Kept |
void |
Voided with a reason, never exported | Kept if it had one |
A voided journal keeps its number, so the numbers stay gapless and an auditor can account for every one.
The rules a journal must pass
A module's proposal is checked before anything is stored. Some problems refuse it outright. The module fixes its own data and tries again:
- It must balance in every currency. For each currency on the journal, the debits must equal the credits. The
refusal names each difference, for example
unbalanced: SGD debits 10000 and credits 9000 differ by 1000 minor units (more debit). Two currencies that are each off are never netted against each other. An unbalanced journal can never become ready. - Every account must exist and belong to the journal's entity or be shared by all entities. Another entity's account is refused.
- Every dimension and value must exist, as must every tax code and vendor or customer named on a line.
Other problems leave the journal as a draft. The rest of its data is fine, and someone has to fix the reference data
first. These are a missing exchange rate, an account, dimension value or tax code that was made inactive, and a vendor
or customer that is blocked. A draft puts an exception on the exceptions queue: fx_missing when a
rate is what is missing, else journal_blocked. Once someone fixes the cause, Retry checks the journal again. It
becomes ready with its number if nothing blocks it any more.
Exchange rates and the functional currency
Each line is converted into the entity's functional currency at one rate per currency. The module may give the rate it used (for example a bill's own rate). Otherwise Finance takes the latest rate on or before the journal's date (exchange rates) and never guesses. Rounding is half to even per line. Any rounding left over (a minor unit or two) goes onto that currency's largest line on the short side. The functional amounts then balance too.
Locked periods
A journal posts in the month of its date. If that month is locked, the journal posts in the
next month that is not locked and keeps a note, for example Dated 2026-09-28; period 2026-09 was locked, posted in 2026-10. A module that must not roll forward can ask for the journal to be refused instead (period_locked).
Idempotent by source
Each proposal carries a source key, by default the record's kind and id (bill:B-1042). Proposing the same key again
with the same content returns the first journal, so a module that retries after a crash never makes two. The same key
with different content is refused. Journals are never edited: reverse the first one and propose under a new key.
Correcting a journal: reverse, never edit
Reverse posts a new journal that is the mirror image of the original: every debit becomes a credit and every credit a debit, with the same accounts, rates and functional amounts. It is ready with its own number. The two are linked both ways. The reversal is dated the original's date unless you choose one. A locked month rolls forward as above. Reversing the same journal again returns the same reversal. A reversal is never reversed again: propose a new journal instead.
Void is for a journal that was never exported (draft, ready or failed): it stays in the outbox, marked void, with your reason. A posted journal is never voided: reverse it. A reversal and the journal it reverses are never voided either.
Void also checks where the journal is on its way out. A journal in an open export batch is refused, naming the batch: its file may already be in your accounting system. Cancel the batch first, or confirm it and reverse the journal. A journal being posted through a connection is refused until the push settles. A posted journal, by a confirmed batch or through a connection, is only reversed, and the reversal is exported like any other journal. The journal's detail shows where it is (in batch EXP-…, posted by batch EXP-…) and offers only the action that is allowed. Voiding and making a batch take their locks in one order, so a void racing a batch create ends either voided and out of the batch, or in the batch and not voided.
Who may do what
| Action | Who |
|---|---|
| List and open journals | Anyone whose Finance roles include journals.read: a controller, a clerk, an approver, a payment preparer, an auditor (in their months) |
| Retry, void, reverse | journals.write: a controller on the journal's entity |
A member scoped to some entities sees only their journals. Another entity's journal answers as if it did not exist. Every proposal, retry, void, reversal and export lands on the event chain in the same transaction. Open a journal's History to see the events.
Tools and API
| Tool | REST | What it does |
|---|---|---|
finance_journal_list |
GET /api/v1/finance/journals |
The outbox, filtered by status, entity_id, period, source_kind with source_id |
finance_journal_get |
GET /api/v1/finance/journals/{id} |
One journal with its lines |
finance_journal_retry |
POST /api/v1/finance/journals/{id}/retry |
Check a draft again, or make a failed export ready again |
finance_journal_void |
POST /api/v1/finance/journals/{id}/void |
Void with reason |
finance_journal_reverse |
POST /api/v1/finance/journals/{id}/reverse |
Post the reversal, optional date and memo |
Reading needs OAuth scope finance:read. The three actions need finance:write. An organisation without a Finance
module gets 403 product_not_enabled.
For module builders
A module proposes inside its own database transaction, so the journal commits with the change that caused it:
import { proposeJournal } from "@/lib/finance/core/journal.ts";
import { billAccrual } from "@/lib/finance/core/journal-builders.ts";
import { announce } from "@/lib/finance/core/exceptions.ts";
const r = await tx((c) =>
proposeJournal(c, {
tenant, actor: "system:payables", entity_id: bill.entity_id, date: bill.date,
source: { module: "payables", kind: "bill", id: bill.id },
lines: billAccrual({ currency: "SGD", party_id: bill.party_id, payable_account_id: ap, lines: [{ account_id: supplies, amount_minor: 10000n }], tax: [{ account_id: gst, amount_minor: 900n }] }),
}),
);
await announce(tenant, r.raised); // a draft's exception, after the commitThe builders in journal-builders.ts cover the journals the modules make: billAccrual, payment, expenseClaim,
salesInvoice, cashApplication, writeOff and reconAdjustment. Each takes account ids and bigint minor units and
returns balanced lines. Connectors mark the outcome of an export with markJournalPosted and markJournalFailed.