Sequence Admin Setup

Developer guide for the Enezaframework sequence generation. Part of the Sequence Generation series.

Table of Contents

  1. Overview
  2. Creating a Configuration
  3. Format Settings
  4. Entity Settings
  5. Managing Configurations
  6. Example Configurations
  7. Related Guides

Overview

A sequence only generates for a document type that has an active SequenceConfig. The admin is the normal place to create and edit those records. This page covers the fields you set and the constraints to respect.

flowchart LR
    A["Admin: Number Sequences"] --> B["Choose Document + Module"]
    B --> C["Set prefix, delimiter, length"]
    C --> D["Set active = True"]
    D --> E["Model.save() finds the config"]

Creating a Configuration

  1. Navigate to System Administrator → Number Sequences.
  2. Click Create New (or edit an existing row).
  3. Fill in the fields below.

Basic settings:

Field Guidance
Document The document type the model uses as document_name.
Module The module category for organization.
Active Check to make this the config generate_sequence() uses.

Format settings:

Field Guidance
Prefix Alphanumeric prefix (CUST, INV, PO).
Delimiter One character between prefix and number (-, _, /).
Number Length Number of digits (4 → 0001, 6 → 000001).

Next number:

Field Guidance
nextnumber The first number to hand out. Start at 1 for new data, or higher to continue an existing series.

Format Settings

The generated value is:

text
prefix + delimiter + zero_padded(nextnumber, number_length)
flowchart LR
    P["prefix: CUST"] --> V
    D["delimiter: -"] --> V
    N["nextnumber: 1, length: 4"] --> V
    V["CUST-0001"]
  • number_length pads with leading zeros; a number wider than the configured length is not truncated.
  • Changing the format later affects only numbers generated after the change.

Entity Settings

entity scopes a configuration to a company in multi-tenant deployments. Leave it blank to apply the configuration across entities.

generate_sequence() filters by documents and active only — not by entity. It returns the first matching active config. If you rely on per-entity sequences, make entity part of your lookup logic and ensure the query is scoped consistently.


Managing Configurations

Task How
Change the format Update an existing config, or deactivate it and create a new one.
Keep history Limited by the constraint — see below.
Reset numbering Set nextnumber back (reuses numbers; use with care).

Constraint: SequenceConfig has UniqueConstraint(fields=['documents', 'active']) (models/enezasequence.py:28-31). For a given document type, at most one row can be active=True and at most one row can be active=False. You therefore cannot keep multiple inactive configurations as an archive for the same document. See Sequence Configuration Model.


Example Configurations

Document Prefix Delimiter Length Format example Notes
Customer CUST - 4 CUST-0001 Start at 1.
Invoice INV - 5 INV-00001 Start at 1001 to continue an existing series.
Purchase Order PO / 3 PO/001 Short format.
Employee EMP - 4 EMP-0001 HR module.