Company-specific accounting mappings
Company defaults and chart activation
Section titled “Company defaults and chart activation”Use erp_addon_account::mapping::CompanyDefault in a caller-owned transaction. A key identifies one
company and a DefaultRole. Chart packs can parse the stable role keys receivable, payable,
income, expense and stock_valuation with DefaultRole::from_key. Resolve each pack’s account
identifier to an account.account record in that company before calling install_if_absent.
A return value of false means the company already has that default, which may be explicitly empty.
Propagate errors from setup so they roll back the chart activation.
At the chart activation boundary, erp_cli::module::chart_defaults::ChartAccountDefaults::prepare
maps company defaults from a staged res.company record to installed account IDs. Pass the
identity map of the selected template using each account reference’s canonical pack key. The five
mapping fields are receivable_account_id, payable_account_id, income_account_id,
expense_account_id and account_stock_valuation_id. Omitted fields leave the company alone.
Explicit template clears prepare empty choices, and unresolved references fail before writing
any role. apply uses the activation transaction and rolls back every choice on refusal.
The surrounding activation workflow owns authorization to activate a release and any approved
replacement of settings an administrator edited.
set records an ordinary change. A user needs company write and accounting-manager permission.
The target must be readable, active, applicable to the company and valid for the role. The
receivable and payable roles require their exact ledger account types. Income and expense follow
the shared posting-account domain. The stock valuation role accepts current, non-current, fixed
and prepayment asset types. A branch can use an eligible ancestor’s account through its own key.
resolve returns the account or an empty choice. require raises a configuration error when the
role has no account. Both accept ResolutionDate::Current for the company’s business date at
transaction start and ResolutionDate::Document for a supplied business date. An invalid configured
account produces an error. A role’s first revision applies to earlier dates, and ordinary
changes after that first revision apply from the transaction’s local business date.
The installed res.company.account_stock_valuation_id field reads and changes the same
stock_valuation key for the selected company, using its current business date. Company write
and accounting-manager permissions are both required. Create the company before assigning this
field. An explicit clear remains empty after chart seeding. Document consumers use
CompanyDefault::require with their explicit date. Filtering on this computed field is unavailable.
The field uses the caller’s record environment, including when it differs from the transaction’s
original user. Account suitability changes invalidate cached field values within the transaction.
An existing installation receives the four mapping tables and the role declarations through the
normal native account upgrade with the matching release artifact. Role data uses stable external
IDs, and account values come from the chart. Companies can have no mapping keys before a chart
loads. Apply the standard runtime grant verification for the new tables before activation.
The remaining sections describe the full ADR 0141 property design. Partner, product and category field adapters and search, account-merge lifecycle, posting evidence and sealed-horizon guards are follow-up work.
Company-specific account properties
Section titled “Company-specific account properties”Account choices on a partner, product template or product category belong to one company. A proposed mapping records a typed subject, company, account role and account reference. A variant uses its template’s account properties. Account roles include receivable/payable, income/expense and stock valuation where appropriate to the subject. Journals remain separately typed configuration.
Ordinary fields read and search the effective property value: an explicit account or false value, otherwise the declared company default for that property. Writing the company-default value stores no independent override, so a later default change reaches that record. An explicit different account stays fixed. False against a nonempty default stays explicitly empty; restoring the default removes that override. Raw-override inspection is a separate internal operation. The property default is scoped to its subject kind: a category income default does not automatically fill the template field. The product business resolver can still obtain an account from its category. Global and per-user account defaults are excluded.
Company receivable/payable defaults feed partner properties and invoice term selection. Existing move accounts retain priority; after the effective partner choices are exhausted, a missing configuration error replaces arbitrary active-account selection. Fiscal-position mapping follows selection.
Resolution and history
Section titled “Resolution and history”The proposed resolver accepts bounded batches with explicit company, business date, required roles and the caller’s transaction. It retains the configuration revision used. A missing required account is an error after permitted fallbacks are exhausted. An invalid configured account is an error immediately; it cannot silently become a default.
Configuration changes append dated Account, Empty (explicit false), or Clear (inherit again) revisions. Company generations identify snapshots. Optional expected versions detect changes to the individual mapping key; unrelated edits in the same company do not cause a conflict. Ordinary writes without an expected version are accepted with last-writer-wins per key. Posted valuation contributions retain their selected account and category evidence; later edits do not reinterpret their reports. Transfers/corrections have explicit effects.
Authorized account/partner merges append target mappings and lineage. Identical destination choices coalesce; conflicting choices require an explicit validated resolution. Source identities remain tombstones while old FK references exist. Segment payloads are not rewritten. Journal deletion is likewise restricted while retained configuration references it.
Role policies define direct-category versus ancestor traversal, applicable costing modes, the property-default association and post-resolution hooks. Price difference uses only the direct category for standard cost, without a parent/company price-difference fallback. Close balancing uses direct category then closing-company valuation; stock posting uses its company journal. These callers must not be forced through one generic fallback chain.
Access and integration
Section titled “Access and integration”Mapping rows obey company and subject access rules even for shared products or contacts. Account applicability checks remain separate from authorization and stay active under elevation. Shared category edits authorize companies whose accounting dependencies change, not every company with a shared product. Database guards cover mapping writes and account/journal applicability changes, including guarded SQL/import paths. See company consistency for the existing company context and integrity rules.
Future addons consume declared account roles through the accounting addon API. Bridges supply stock integration. Chart installation, effective property wiring and rendered settings have their own acceptance checks.