Every document number in DrootERP comes from a number series: a platform.number-series record that says which
text field of which model it numbers, and how. A series is the tenant's data. Admins edit it in Setup › Number Series
(prefix, digits, suffix, company, conditions, when the number is given). An app declares which fields are numbered and
seeds the default series. It never hard-codes a prefix and never counts on its own.
The number
prefix + counter + suffix. The counter is zero-padded to the series' digits (padding, 0–15). The prefix and
suffix are text with tokens:
| Token | Gives |
|---|---|
{entity} |
the record company's document code (platform.entity.documentCode, else its key in capitals) |
{fy} |
the fiscal year code, in the company's books format (accounting.books: start month and fiscalYearFormat, e.g. 2026-27); a calendar year without accounting |
{fyStart}, {fyEnd} |
the fiscal year's start and end years |
{year} / {yyyy}, {yy}, {mm}, {dd} |
the record's date |
{field:<key>}, {field:<lookup>.<key>} |
a value of the record, or of the record a lookup names (a branch's code) |
The record's date is the series' dateField, else the declaration's dateField, else the model's periodField, else
the company's today.
Declaring a numbered field
{ "key": "fleet.trip", "label": "Trip", "scoped": true, "titleField": "number",
"numbering": [{ "field": "number", "dateField": "tripDate" }] }
ModelDef.numbering is a list of:
field: a text field of the model. Mark itreadOnlyso people can't type it, unless a series allows manual numbers.assignOn:["create"](the default) or the transitions that give the number (["post"],["submit"]).dateField: the date or datetime field the number is dated by.byDomain:truewhen the app's own server code gives the number (a posting, a release, throughkernel.numbering.next), for instance per legal entity on a document scoped to a site. The write step never numbers such a field, and its series take no "when given" and no manual numbers. A ledger model's numbered field is always given this way.optional:truewhen a record may go without a number; otherwise a write that no series numbers is refused ("No number series numbers … : add one under Settings › Number Series").
The kernel numbers the field in every record write (RecordCommands). It runs after the before_* scripts and derived
values, and before computed values and the kernel's checks, so a computed title and a required check see the number:
- On create, a field that the series gives at creation gets a number when the write leaves it blank.
- On a transition that the series names, a field that is still blank gets its number.
- A value the write gives itself is kept when the series allows manual numbers or the write is the system's (a domain's posting, a script). A user's value is refused otherwise. Either way, a number already used is refused.
An admin may also number any text field that no app declares, such as an item's code, with a series of their own.
Seeding the default series
Seed rows into platform.number-series (the app depends on platform ^1.16.0):
{ "model": "platform.number-series", "key": "key", "records": [
{ "key": "fleet.trip", "name": "Trips", "modelKey": "fleet.trip", "fieldKey": "number", "prefix": "TRP/{entity}/{fy}/", "padding": 5 }
] }
Seeds are inserted once and become tenant data. An app that numbers one field per document type (accounting's journal
number) seeds one series per type, with a condition:
"conditions": [{ "field": "documentType", "op": "eq", "value": "vendor-bill" }].
Condition operators: eq, ne, in/nin (a comma list), blank, present.
Choosing a series: the record company's own first, then its legal entity's, then the group's. A series with more
conditions wins over one with fewer, then the lower priority. Validity dates (validFrom, validTo) are judged on
the record's day.
Counters, gaps and duplicates
- A counter belongs to a series and a period. With
restart: "auto"(the default), the period is the values the prefix's and suffix's tokens take ({fy},{mm},{field:branch}…), never their literal text:{fy}restarts each fiscal year, while an admin's new prefix or a company's new document code carries the count on.perCompany(on by default, the group rule) counts each company on its own; off, the group shares a counter (one per company still when the text shows{entity}).restart: "never"keeps one running counter. - Gapless series (the default) increment inside the command's transaction. A refused save gives its number back. A dry run or preview never moves a counter that stays.
- A new counter starts after the highest number its text already has in the data, which covers imported documents and numbers given before the series existed. A number found taken is skipped. No number is ever given twice.
- Admins see each series' counters and may set the next number. A value at or below a number in use is refused.
In server code
A posting domain that writes the number itself (a ledger model, which the write step never numbers) takes it from the series:
const number = await kernel.numbering.next(uow, {
modelKey: "accounting.journal", field: "number", record: { documentType, date }, company: book,
tokens: { fy: period.fiscalYear }, // what the domain already knows: `fy`, `entity`
});
The record is what a series chooses on: its conditions and {field:…} tokens read it. Pass the document as it will be
stored (every value the write will keep that a series might name: the company it belongs to, its source, its header
values), not only the date and type: a condition on a value the call leaves out reads as empty and never holds, so the
series is passed over for a broader one.
kernel.numbering also has preview, counters, setNext, listSeries and catalog, which the admin API uses:
/api/numbering/*, capability numbering.admin.
Reading which series a record meets
kernel.numbering.explain(uow, { modelKey, field, record, company }) answers, without taking a number, every live series
of the field with whether its company, dates and conditions fit the record, and which one wins. A domain uses it to check
a rule over the series instead of choosing again (accounting's "a branch with its own series must be numbered by it").
Locking a series
A series is a company's legal sequence, so what decides which documents it numbers can be locked: set its Locked flag
(locked, Setup › Number Series). While locked, a save that changes one of the fields the lock keeps is refused with 409 (details.reason
series_locked, details.fields the changed ones), and it cannot be deleted. The format (prefix, digits, suffix) and the
name stay editable. The fields a lock keeps are a setting, platform.numbering › What A Lock Keeps: every one of company,
conditions, priority, active, valid from and to, when it gives its number, the document type and the field by default;
take a field off only when it is changed on purpose while a series is locked. The same setting's Ask Before Changing
What A Series Numbers (on by default) makes Setup list a coverage change and ask to confirm before it is saved.
Unlocking is its own save: a write that unlocks and changes one of those at once is refused. A save
that sends the same values for the locked fields (the Setup screen sends every field) is not a change. An app's seed is
not a user's edit and is not held by the lock. Every change, the lock itself included, is a record change in the audit log.
Moving an app's own ranges onto series
The number-series migration step turns an app's own range rows into series and keeps the tenant's prefix and digits.
Because counters start after the highest number already given, nothing else needs copying:
{ "op": "number-series", "model": "platform.number-series", "from": "sales.number-range", "match": "code",
"series": { "order": { "key": "sales.order", "model": "sales.order", "field": "number" } } }
- A company-scoped range model becomes company series (
<key>@<company>). "*"maps every code, with{code}replaced in the key and the values.prefixes: { "before": "5.0.0", "map": { "JV/{fy}/": "JV/{entity}/{fy}/" } }rewrites a range that is still on an older release's seeded prefix, for installs upgrading from before that release.prefixField,paddingField: the range's fields when they aren'tprefixandpadding(a document type's ownnumberPrefixandnumberPadding; with"*"and a condition onorderType.code, one series per type).chosenBycarries over which range other rows picked by its code. With{ "model": "inventory.settings", "field": "numberRange", "company": true }, a company's pick becomes<key>@<company>. With{ "model": "inventory.movement-type", "field": "numberRange", "condition": "movementType", "value": "code" }, a type's pick becomes a group series for that type's records. A mapping with"onlyChosen": truegives only those picks, with no group series of its own.