How to Create Sequence Numbers in Odoo 18

Hello Odoo Learners and Developers!

Welcome to this hands-on guide to Odoo!

Whether you're managing books, customers, products, or tickets, sequence numbers are key to making your records organized, unique, and traceable. In this beginner-friendly blog, I'll show you exactly how to create custom sequence numbers in Odoo 18 using two simple methods:

  •  Method 1: Using Python code (for developers)
  •  Method 2: Using Odoo UI (for functional users)

We'll create a small Learn Odoo Management module where each lesson gets a unique name like Lessons/00001, Lessons/00002, etc.

By the end of this post, you'll be able to add sequence numbers to any custom model, even if you're new to Odoo development!

Why Do We Use Sequence Numbers in Odoo?

Using sequence numbers helps assign a unique identifier to each record, making it easy to manage and track business processes. Organizations can avoid duplication, improve transaction control, and assign sequence numbers to invoices, orders, or products. This practice of reporting accuracy enables smoother system integrations and data integrity. Sequence numbers also support compliance by creating an audit trail, preventing errors, and helping to detect discrepancies or fraud.

  • Uniqueness: Each record (like an invoice, book, or order) has a different ID.
  • Traceability: Makes it easier to search and track a record's history.
  • Customization: You can define prefixes, padding (00001, 00002), and date-based sequences.

Method 1: Create a Sequence via Code


Step 1: Define Your Model

Let's say we're building a model called odoo.lessons. Here's how you define the model and add a name field that uses a sequence:

 Explanation:

  • Name  is a Char field with default 'New'.
  • The create() method checks if it’s 'New', and then calls Odoo’s sequence engine using next_by_code('odoo.lessons').

Step 2: Define the Sequence in XML

Create a file data/ir_sequence_data.xml and add:

 Key Fields:

  • prefix: Adds "Lessons/" before the number.
  • padding: Makes numbers like Lessons/00001,.
  • code: Must match the one used in Python.

Step 3:Add this inside the Form View to display the auto-generated sequence number (Reference/Name) at the top of the form.

  • This is usually placed inside the <sheet> tag under <form>, like this:

  • The name field shown here is an auto-generated sequence number, like Lessons/00001,Lessons/00002, etc.
  • This number is created automatically when you make a new record in odoo.lessons model.
  • It's readonly so users can't change it.

Don't forget to load this XML in your __manifest__.py:

Step 4: Test It

Once your dev_learn_odoo module is installed:

  1. Go to the Learn Odoo menu (or wherever you've added your menu).
  2. Click Create to add a new lesson.
  3. Fill in the lesson details like:
  • Trainee
  • Lesson Price
  • Lesson Date

Leave the Reference Number (i.e., name field) as it is — it will be automatically generated!

Click Save.

You'll see the Reference Number auto-filled as something like:

How to Create Sequence Numbers in Odoo 18

Method 2: Create a Sequence from the Odoo Interface (No Code)

This is perfect for non-technical users or quick admin setups.

Step 1: Go to Settings

  1. Enable Developer Mode (Settings > Activate Developer Mode)
  2. Navigate to:
    Settings > Technical > Sequences & Identifiers > Sequences
    How to Create Sequence Numbers in Odoo 18

Step 2: Create a New Sequence

Click Create and fill in the details: 

  • Name: Odoo Lessons Reference Number
    Code: odoo.lessons (must match what’s used in Python)
  • Prefix: Lessons1/
  • Padding: 5
    Number Next: 1
  • Number Increment: 1

Then Save the sequence.

That’s it! Now, any model calling next_by_code('odoo.lessons') will use this sequence.

How to Create Sequence Numbers in Odoo 18

1. Use Date-Based Sequences (Auto-Reset Monthly or Yearly)

Want your numbers to reset every month or year?

Just enable this setting when creating or editing a sequence:

Use subsequences per date_range

Then choose how often it should reset   for example:

  • Monthly: Starts from Lessons1/2025/01/00001  every new month.
  • Yearly: Starts from Lessons1/2025/00001  every new year.

Perfect for things like:

  • Monthly reports
  • Yearly contracts
  • Sales orders by year

2. Standard vs. No Gap

Odoo lets you choose how strictly numbers are generated:

  • Choose Standard if:

    • Allows gaps in numbers.
    • Useful for internal use (like logs, testing, or reports) where exact sequence numbers are not critical.

        Example:

            You are creating internal documents:

      1. First record: Lessons1/00001
      2. Second record: Lessons1/00002
      3. You delete the second record.
      4. Third record: Lessons1/00003
        Now the sequence looks like:

             Lessons1/00001  

            ❌ Lessons1/00002 (deleted)  

             Lessons1/00003

             Notice: Lessons1/00002 is missing. That’s okay in Standard mode.

  • Choose No Gap if:

    • No missing numbers are allowed.
    • Used for essential documents like invoices, legal forms, or official records, where every number must be tracked.
    • If a record fails to save or is cancelled, that number is either reused or blocked until it is used.

       Example:

          You're creating invoices:

    1. Invoice 1: INV/00001
    2. Invoice 2: Odoo tries to generate INV/00002, but the action fails (e.g., validation error).
    3. Odoo will not skip this number — it will retry or wait until it can safely assign INV/00002.

Your sequence remains:

      • INV/00001  
      • INV/00002  
      • INV/00003

There are no gaps, even if something fails during creation.

Conclusion :

Creating sequence numbers in Odoo 18 is easy, flexible, and accessible for all users. Whether you're a developer writing Python code or an admin setting it up through the user interface, Odoo 18 offers simple solutions to enhance record management. Custom sequences help maintain organized and traceable records across modules. With this guide, you can easily set up sequences for any model in Odoo.

Check out our blog on how to Create Sequence Numbers in Odoo

Odoo DEV May 22, 2025
Share this post
Archive
Sign in to leave a comment
How to add chatter in odoo 18