OdooWiki OCA HUB

Sequence from Python expression

sequence_python folder_open OCA/server-tools open_in_new
Generic Modules License: AGPL-3

This module allows to generate a sequence by a Python formula expression.

Besides common Python functions and operators, it provides several functions like 'random' and 'uuid' in the expression, as well as variables such as the next number in the sequence. These are also listed next to the input field on the sequence form view.

If you want to add more variables for use in the expression, you can extend this module.

Use cases for this module could be:

  • You want to generate alphanumeric numbering
  • You want to apply some math to the number to prevent customers from knowing their place in the sequence
  • You want to use UUID

auto_awesome What this module does

AI-generated from the code · Odoo 19.0

Lets you build sequence numbers with a Python formula instead of a plain counter, so you can create alphanumeric codes, random values or UUIDs. A new 'Python Code' tab appears on sequence forms with a live preview.

This module extends the standard sequence configuration in Odoo. On any sequence form you now get an extra 'Python Code' tab where you can switch on 'Use Python' and type a Python expression that produces the next sequence value.

  • The expression is evaluated each time a sequence number is requested, and the result is combined with the sequence's prefix and suffix.
  • Several ready-made variables are available: number (the next integer), number_padded (the number padded with zeros according to the sequence padding), sequence (the sequence record itself), plus the random, uuid and string modules for random or unique values.
  • A 'Preview' field shows immediately what the next generated value would look like, or the error message if the expression is invalid.
  • If 'Use Python' is off, the sequence behaves exactly as before.

Typical uses are alphanumeric numbering, hiding the real order of documents by applying maths to the number, or generating UUID-based references. The module only touches the sequence model ir.sequence and its form view; it does not change how other documents call sequences.

Depends on

base
Models and fields (1)
  • ir.sequence · extends an existing modelpython_code (Python expression), use_python_code (Use Python), python_code_preview (Preview)

Text generated by AI (DeepSeek) from reading the Odoo 19.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 7 confirmed, 2 with no information of 9 versions.

Sources · Odoo 15.0

Confirmed on 2026-11-03 in branch 15.0 of OCA/server-tools.

terminal Installation and usage

OCA documentation · Odoo 19.0

To use this module, you need to:

  • Go to the form view of an ir.sequence record
  • Go to the Python tab
  • Enable the 'Use Python' checkbox
  • Change the default 'number' expression to something more fancy.

Examples:

# To separate the Odoo-generated number with hyphens eg. 0-0-0-0-1
'-'.join(number_padded)

# To have an UUID as the sequence value
uuid.uuid4().hex

# To use an 8-digit binary number
'{0:#010b}'.format(number + 300)[2:]

And so on.

No verified information in OCA: Installation, Configuration.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.