Enable Dark Mode!
By: Aswathi PN

How to Create Sequence Number in Odoo 15

Technical Odoo 15

The creation of Sequence numbers is a very simple process. We can identify each record using its sequence number, which will be unique for each record.

For that first of all create a field for storing the sequence


reference_no = fields.Char(string='Order Reference', required=True,
                          readonly=True, default=lambda self: _('New'))

And add function for the sequence as depicted in the following set of code.

def create(self, vals):
   if vals.get('reference_no', _('New')) == _('New'):
       vals['reference_no'] = self.env['ir.sequence'].next_by_code(
           'hospital.patient') or _('New')
   res = super(HospitalPatient, self).create(vals)
   return res

And then create a record for that and create an XML file for that.

   <record id="seq_hospital_patient" model="ir.sequence">
       <field name="name">Patient Sequence</field>
       <field name="code">hospital.patient</field>
       <field name="prefix">HP</field>
       <field name="padding">5</field>
       <field name="company_id" eval="False"/>

The XML code must inside a data tag.

<record id="seq_hospital_patient" model="ir.sequence">

The ID is the ID of that record, it is unique for each record. And that record will be stored in the ir.sequence table.

<field name="name">Patient Sequence</field>

name - is the Name of the record that will be created on the specified model.

<field name="code">hospital.patient</field>

Code - is the sequence code for the record.

<field name="prefix">HP</field>

Prefix - is a character field that gives the prefix of the sequence for the record.

<field name="padding">5</field>

Padding - is the size of the sequence. We can decide the size.

In the below screenshot we can see a sequence number is generated with a prefix of HP and the number is 00001  the first number is automatically generated as 1 and we create another record in the same model that will be 2 and so on and also here we can see the padding of the number is 5 that we will mentioned in the code.


We can configure the sequence number from the general setting of Odoo

Go to General Settings > Technical > Sequences & Identifiers > Sequences

In the below screenshot we can see the all sequence numbers that are created for some record we can directly create a sequence number from the frontend by clicking on the create button.


In the below screenshot we can see a record is created corresponding to the above code


In this see the details of the record like name, code, prefix, suffix, sequence size, step, next number, etc.

For sequence numbers, there are two implementation methods that are 

- Standard

No gap

No gap means there is no gap between the sequence numbers of each record.

For example, there is a record created for Patient sequence the sequence number is HP00001, and create another record that will be HP00002. Then we delete the second one and create a third record. In the case of the, No gap implementation method that will be HP00001 but in the case of standard implementation sequence will be HP00003.  In most cases, we use the Standard implementation.  

By enabling the “Use subsequences per date_rage” we can set the date range for sequences.


In conclusion, the Sequence creation number can be defined with ease in Odoo 15.

If you need any assistance in odoo, we are online, please chat with us.


Candi Smith

Thank you for sharing this information It will help me for creating reports.




Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message