Bank Payment Files
Vendor payments leave the system in one of three ways: keyed in at the bank’s own website (no payment method), sent in a bank file the bank executes (a SEPA credit transfer, a US ACH/NACHA file), or printed as a check. Accounting ships the shared machinery; each scheme is a small module that plugs one file format into it. This page is for adding another scheme — a UK Bacs file, a Canadian CPA-005 file, a bank’s own CSV.
The pieces you build on
Section titled “The pieces you build on”| Record | What it holds |
|---|---|
PaymentMethod | One row per scheme, shipped as data by the module that implements it. code is the stable handle your code keys on; kind is Bank File or Printed Check; currency limits the scheme to one currency (blank for any). |
BankAccount | A payee’s (or the company’s) account: iban + bic, or routing_number + account_number + account_type (Checking/Savings), plus bank_name and bank_country. |
Payment | payment_method, bank_account (the payee’s account) and payment_batch. |
Journal | bank_account (the company account payments are drawn on) and outbound_payment_method (the default). |
Contact | vendor_payment_method — the vendor’s own preference. |
PaymentBatch | The posted vendor payments of one method, one bank journal and one currency, sent as one file. |
A vendor payment’s method defaults from the vendor’s preference, then the bank journal’s default. When the vendor has exactly one bank account in the payment’s currency, that account is filled in too.
The payee’s account number is a secret: it is an Encrypted field, so it never reaches the
browser (a form shows ••••••••) and every change to a bank account is tracked. Your file
builder reads it in Python as plain text, like any encrypted field. Show account_last4 (kept in
step with the number) or the record’s name wherever a person has to recognise the account.
Adding a bank-file scheme
Section titled “Adding a bank-file scheme”1. Ship the method
Section titled “1. Ship the method”- data_type: PaymentMethod identifier: payment_method_bacs name: Bacs Direct Credit code: bacs kind: Bank File currency: GBPTurning the module on is enough to offer the method on vendors, journals and payments, and to let a Payment Batch be created for it.
2. Answer the batch’s two questions
Section titled “2. Answer the batch’s two questions”Extend PaymentBatch and override two hooks. Every scheme extends the same model, so each
override checks that the batch is its own and passes everything else to super() —
otherwise installing two schemes makes one of them silently stop working.
from fullfinity.engine.base import *
class PaymentBatchBacs(Model): __inherit__ = "PaymentBatch"
async def _is_bacs(self): await self.fetch_related("payment_method") return self.payment_method.code == "bacs"
async def _payment_problem(self, payment): """Why this payment can't go in the batch, or None.""" if not await self._is_bacs(): return await super()._payment_problem(payment) problem = await super()._payment_problem(payment) # e.g. no payee account at all if problem: return problem await payment.fetch_related("bank_account") if len(payment.bank_account.routing_number or "") != 6: return t("{ref}: the payee account needs a six-digit sort code.", ref=payment.number) return None
async def _build_bank_file(self): """The file: (filename, mimetype, content bytes).""" if not await self._is_bacs(): return await super()._build_bank_file() await self.fetch_related("journal", "journal__bank_account", "payments", "payments__bank_account") text = build_my_bacs_file(self.journal.bank_account, self.payments, self.execution_date) return f"bacs_{self.id}.txt", "text/plain", text.encode("ascii")What the batch does around your hooks:
- Collect Payments gathers every posted vendor payment of the batch’s company, currency
and method that is not already in a batch. A payment
_payment_problemrejects is left out and counted in the result the user sees, with the first few reasons. - Generate re-checks every payment (refusing the whole file if any is rejected), enforces
the method’s currency, calls
_build_bank_file, stores the file on the batch and freezes it. Generate runs elevated, so the builder can read the company’s bank details for any user allowed to generate. - Once the file exists, the payments’ method, payee account and batch can no longer change — the file has been issued with them. An administrator can reset a batch whose file the bank rejected; a file the bank executed must never be reset.
A third hook, _other_entry_count(), is for schemes whose file carries entries that are not
payments (ACH prenotes). Return how many the batch holds, so a batch of only those can still be
generated. The default is 0.
Write file builders as pure functions — no models, no clock, the timestamp passed in — and test them byte for byte. A bank rejects an entire file over one wrong column.
Methods that are not files
Section titled “Methods that are not files”A Printed Check-style method has no batch. If your module dispatches a payment some other way
and must stop its method or payee account changing afterwards, override Payment’s
_dispatch_lock_reason() the same cooperative way: return a sentence saying why the payment can
no longer change, or call super().
async def _dispatch_lock_reason(self): if await self._already_sent_by_my_scheme(): return t("Payment {ref} has already been sent.", ref=self.number) return await super()._dispatch_lock_reason()Reference implementations
Section titled “Reference implementations”- SEPA Credit Transfer — the smallest scheme: an IBAN check and an ISO 20022 pain.001 file.
- ACH Payments (NACHA) — US bank files with remittance addenda, prenotes (zero-dollar test entries that prove a new payee account), per-journal origination settings, and recording returns: a returned payment is cancelled, reopening its bills, and an account the return says cannot receive money is marked failed until corrected.
- Check Printing — a
Printed Checkmethod: printing on pre-printed voucher stock, the check register (a used number is never reused; spoiled checks are voided), and the Positive Pay file a bank uses to pay only the checks you issued.
ACH return codes are one shared catalogue (ACH_RETURN_REASONS in invoicing’s _ach helper),
used both by these vendor files and by online-payment bank debits.