
How To Generate Sequence Numbers In Odoo 16
Odoo 16 is a powerful and widely used enterprise resource planning(ERP) software that can help businesses streamline their operations and increase efficiency. With the built-in features of Odoo 16, it can be easy to generate sequence numbers for various business documents such as invoices, purchase orders, and quotations. In this blog post, we will explore how to generate sequence numbers in Odoo 16 and customize them according to your business needs.
Also Read: Key Features of Odoo 16
A sequence number is a unique identifier used for various purposes, such as generating unique IDs for your records. Check the step-by-step guide to generate sequence numbers in Odoo 16.
Steps to Generate Sequence Numbers in Odoo 16
In Odoo 16, you can generate sequence numbers using the built-in sequence feature. Follow the steps below:
- "Manual": This option allows you to enter the sequence numbers manually.
- "Numbering": This option generates the sequence numbers automatically based on the defined pattern.
- "Date Range": This option generates the sequence numbers based on the date range specified.
Step 1: Navigate to the Sequences Menu
Go to the Odoo menu and select "Technical" -> "Sequences & Identifiers" -> "Sequences".
Step 2: Create a New Sequence
To create a new sequence, click on the "Create" button.
Step 3: Define Sequence Name
In the "Name" field, enter a clear and descriptive name for your sequence. This name will help you identify the purpose of the sequence later. For example, if the sequence is for generating invoice numbers, you could name it "Invoice Sequence."
Step 4: Assign a Unique Code
In the "Code" field, enter a unique identifier for the sequence. This code is used internally by Odoo to reference the sequence when assigning numbers.
Step 5: Choose the Implementation Method
Odoo offers different ways to generate sequence numbers. Select the option that best suits your needs from the "Implementation" dropdown menu:
Step 6: Set the Starting Number
In the "Next Number" field, enter the starting number for the sequence. This is the number that will be assigned to the next record created using this sequence.
Step 7: Customize Sequence Format (Optional)
The "Prefix" and "Suffix" fields allow you to add text that will be automatically included before and after the generated sequence number, respectively. For example, you might use "SO-" as a prefix for a sales order sequence or "-INV" as a suffix for an invoice sequence.
Step 8: Define Padding (Optional)
You can set the padding for the sequence number by filling in the "Padding" field. The Padding field allows you to define a minimum number of digits for the sequence number. Odoo will automatically add leading zeros to reach the specified length.
Step 9: Save the Sequence
Finally, click on the "Save" button to save the sequence.
After creating the sequence, you can incorporate it into your module or application by calling it in your code. For example, you can use the following code to get the next number from the sequence:
from odoo import models, fields class MyModel(models.Model): _name = 'my.model' _description = 'My Model' name = fields.Char(string='Name') sequence_number = fields.Char(string='Sequence Number', readonly=True, default=lambda self: self.env['ir.sequence'].next_by_code('my.model.sequence'))
In this example, we have created a new model "my.model" and added a field "sequence_number" to store the sequence number. The default value of the field is set to the next number from the sequence "my.model.sequence".
Explore More: Odoo 17 vs. Odoo 16: What’s New and Improved Features?
How To Generate Sequence Numbers in Odoo 16 With XML File
In addition to using Python code to generate sequence numbers in Odoo 16, you can also use an XML file to define the sequence. Here's an example of how to generate sequence numbers in Odoo 16 using an XML file:
Step 1: Create a New XML File
Create a new XML file in your custom module's "data" folder. For example, if you want to create a sequence for purchase orders, create a file named "purchase_sequence.xml".
Step 2: Define The Sequence in the XML File
In the XML file, define the sequence using the "ir.sequence" object. Here's an example:

In this example, we define a new sequence with the name "Purchase Order Sequence" for purchase orders. The code "purchase.order" identifies the object for which the sequence will be used. We also specify a prefix of "PO/" and a padding of "4" for the sequence number.
Step 3: Load the XML File
Load the XML file into Odoo by adding a reference to it in the "manifest.py" file of your custom module. Here's an example:
{ 'name': 'My Module', 'version': '1.0', 'depends': ['sale'], 'data': [ 'data/my_module_sequence.xml', ], }
In this example, we specify that the "purchase_sequence.xml" file should be loaded when the module is installed.
Step 4: Test The Sequence
After installing your custom module, you can test the sequence by creating a new purchase order. The sequence number should be automatically generated with the prefix and padding you specified in the XML file.
Conclusion
The steps outlined in this blog provide an easy and convenient method to generate sequences in Odoo 16 using an XML file. By following the steps, you can define sequences for your specific requirements and customize theme as needed. With the use of an XML file, defining sequences becomes a straightforward process that can be easily managed by developers.
If you are looking for an experienced Odoo ERP development agency, CodeTrade will help you with a proven track record of successfully delivering complex projects on time. CodeTrade is an Odoo Community Partner, committed to delivering a top-quality solution tailored to your business needs. Contact CodeTrade today to learn more about how our Odoo development services can help your business or Hire dedicated Odoo developers from CodeTrade.