Sequence Number In Odoo 14



The sequential field in Odoo also known as an auto incremental field generates an auto incremental number every time a new record is generated. If we need to add a sequence field for naming in our custom model, we can do this easily by making the name field incremental

Step 1:

We can create sequence number in our enzapps.estimate model.

In Py file you can add one Char field like this:

name = fields.Char(‘Order Reference’, required=True, index=True, copy=False,


Then add this:

By this code we are overrighting the create method  of our specific model.


def create(self, vals):

NoteBy this code it is checking Whether the value of name field is the default

value or not. If it is default value then

if vals.get(‘name’, ‘New’) == ‘New’:

Note: in this code it is searching the ‘test.sequence’ in ‘ir.sequence’ model and

assigning to vals[‘name’]. Here we can mension any name

vals[‘name’] = self.env[‘ir.sequence’].next_by_code(‘test.sequence’) or ‘/’

Note: it is executing the create method by using ‘super’.

return super(TestSequence, self).create(vals)  Here also you can  give any name.



Step 2: Then you can create corresponding xml file:

<?xml version=”1.0″ encoding=”utf-8″?>


<data noupdate=”1″>

<record id=”seq_test_seq1″ model=”ir.sequence”>

           <field name=”name”>VR</field>

           <field name=”code”>test.sequence</field>

           <field name=”prefix”>VR/</field>

            <field name=”padding”>2</field>

             <field name=”company_id” eval=”False”/>





Note: The whole code will be written inside the <data></data> tags.

The noupdate=”1″ is used for not updating this code when the app is upgraded.

The id=”seq_test_seq1″ this is the id of this record which can be given as our


The model=”ir.sequence” is used for specifying the model which the record has

to be created.

The <field name=”name”>VR</field> is the name of the record.

The <field name=”code”>test.sequence</field> is the code which we will use in the python file later for applying inside the code.

The <field name=”prefix”>VR/</field> is the prefix character’s for the sequence


The <field name=”padding”>2</field> is used for specifing the no of Zero’s

after the prefix character’s.


And add thid in field declaration part,

1.Inside the Xml File.

-> We have to add the below code inside the Form view code.

<div class=”oe_title”>


       <field name=”name” readonly=”1″/>




The print will be like this:


To know more about us


Leave a Reply

Your email address will not be published.