Reconciliation of journal items
erp_addon_account::reconcile matches the debit and credit items of one account with each other (ADR 0048 D4 with
amendment A7, ADR 0050 D4/D5). This release covers posted items in the company currency on accounts that allow
reconciliation (account.account.reconcile, always on for receivable and payable accounts).
Models
Section titled “Models”| Model | What it holds | Written by |
|---|---|---|
account.partial.reconcile | One match: debit item, credit item, amount (company currency and each item’s currency), later date of the two, settlement | the service only; unlink unmatches |
account.full.reconcile | The settlement of a component whose items are all settled; its id is their matching number | the service only; unlink alone is refused |
account.open.item | What is still due on a matched item and its component label | the service only; users read it |
Database CHECKs keep a match positive and between two different items, and an open item’s residual between zero and the item’s amount on the item’s side, so an over-applied match fails whatever path writes it.
Fields on journal items
Section titled “Fields on journal items”full_reconcile_id, matched_debit_ids and matched_credit_ids are written by the service only: a caller value or
a default_<field> context key is refused by name. amount_residual, amount_residual_currency, reconciled and
matching_number are computed in one read per batch: from the open-item row when the item belongs to a component that
is not settled, zero when it is settled, else the item’s own amounts. The number is the settlement id, else P with the
smallest match id of the component, else empty. These four fields are not searchable yet.
Matching and unmatching
Section titled “Matching and unmatching”account.move.line.reconcile()takes the items in the order due date (else date), amount in currency, balance, grouped by partner when several take part, and matches debits with credits for the smaller open amount at each step. A settled item whose component has an open item in the selection is left out; any other settled item is refused, naming the entries it is matched with that the caller may read and counting the others. An item without an amount is refused as having nothing to match.- A matched journal item cannot be deleted, not even by SQL: the matches refer to their items with
ON DELETE RESTRICT, and so does an item’s open-item row. account.move.line.remove_move_reconcile()andunlinkof a match remove matches; the residuals of the component are rebuilt from the matches that remain and the settlement goes.unlinkof a settlement on its own is refused (the reference keeps the matches and showsPnumbers again; that comes later).
The posted invoices among the entries get their amount due (what remains on their receivable or payable items) and
their payment status (not paid, partial, paid, reversed) in the same unit, from one function
(reconcile::apply::refresh_moves). The “in payment” status resolves to paid (plan decision L14). A changed status
is reported to the record history (Transaction::track_external), so the invoice thread shows it when the accounting
mail bridge is installed.
Rights and locks
Section titled “Rights and locks”The caller needs account.group_account_user and write access to the items (read access to the matches when it
deletes them); the check runs before any statement reads or locks a caller-named record. One unit takes, in order:
the entry headers of every item reached through the matches (id order, with a version touch), their open items
(line-id order), then the matches and settlements (id order). A second unit racing for the same items fails with a
serialization error and applies nothing. One interactive call may reach at most 2,000 items and 4,000 matches.
Refused until later releases
Section titled “Refused until later releases”Items of draft or cancelled entries; items in another currency than the company’s; write-offs, cash-basis taxes, exchange differences and early-payment discounts. Open-item rows are created at an item’s first match (the line triggers of ADR 0048 D4 are not built), so open-item lookups by account and partner do not cover unmatched items yet.
Dated inputs for removed matches
Section titled “Dated inputs for removed matches”When the reconciliation service removes a company-currency match, its existing transaction writes
two account.reconcile.removal rows, one per journal item. Each row preserves the original partial
ID, its own item ID, partner ID (including null), account, company and currency. The debit item’s
matched_delta is negative and the credit item’s is positive. Relative to the item’s signed
balance, that delta applies for matched_on <= cutoff < removed_on. The company of each endpoint
supplies its own local removal date at transaction start, including matches across branches in the
same company tree. The stored later item date supplies matched_on.
An unmatch before a future-dated match becomes effective contributes at no cutoff.
Both normal unlink entry points share the write. Failure to identify every requested match with dated company-currency endpoints rolls back the whole operation. The history model grants no ordinary RPC access and refuses generic ORM mutation. PostgreSQL blocks updates, deletes and truncation of removal history. The module lifecycle refuses uninstall while removal facts exist. It has no seed data because it records actual unmatching operations. Upgrading adds an empty table. Existing active partials supply dated inputs, while rows removed before capture was installed cannot be reconstructed. Accounting Reports 1.8 consumes these facts. Accounting 1.7 establishes singleton accounting coverage on first initialization. An earlier writer attempting to remove matches without both signed endpoint records fails atomically.