It's quite a simple procedure to add sequences for records in odoo. If an individual needs to add a sequence number for every record of their model, they first have to add a field in their model and need to create a record in ir.sequence in the XML file.
In python file add a field in your model like the below code.
name = fields.Char(string="Service Number", readonly=True, required=True, copy=False, default='New')
Then add a function like in the following code.
def create(self, vals):
if vals.get('name', 'New') == 'New':
vals['name'] = self.env['ir.sequence'].next_by_code(
'self.service') or 'New'
result = super(SelfService, self).create(vals)
After defining function, you need to create a record for this. So create a record in the XML file .
<record id="sequence_self_service" model="ir.sequence">
<field name="name">Self Service</field>
By doing this, a sequence number gets automatically generated, on creating a record in this model.
> name- Name of the record created in the “ir.sequence” model
> code- Sequence code
> active- A boolean field to indicate whether it is active or not
> prefix- A character field, where we can give the prefix of the sequence
> padding- sequence size
> number_next- next number that will be used
> number_increment- the next number of the sequence will be incremented by this.
In the below image -we can see a sequence number is generated for the record with prefix SS and number 000001(odoo will automatically add ‘0’s to the left side of the next number to get the required padding size-here we given padding size =6, so the first sequence number becomes 000001).
We can configure the sequence number from the settings of odoo.
Go to Settings -> Technical -> Sequences & Identifiers -> Sequences
The below image shows the corresponding record of sequence number created using the above code.
There are two types of the implementation method
1. No gap
No gap defines that there will be no gap in the numbering of records.
For example, if a self-service form is created, it will be numbered as SS000001. Then the second will be SS000002. If I deleted the second form and create a third one, then in case of
> No gap- sequence will be SS000002
> Standard- sequence will be SS000003
In the prefix and suffix field, you can add a prefix and suffix of the sequence. You can define the date range for sequence. For this, you have to check the “Use subsequences per date_range” field.
For example, if you want to start sequence number from 1 at the start of every month, then define the date range in the from and to the field and next number as 1.