how-to-add-sequence-in-odoo12.png
Blogger_636842438619363816.jpg
By: Meera K

How to Add Sequence in Odoo 12

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.


For example:

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.


@api.model
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)
   return result


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>
   <field name="code">self.service</field>
   <field name="active">TRUE</field>
   <field name="prefix">SS</field>
   <field name="padding">6</field>
   <field name="number_next">1</field>
   <field name="number_increment">1</field>
</record>


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).


how-to-add-sequence-in-odoo12-cybrosys


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.


how-to-add-sequence-in-odoo12-cybrosys


There are two types of the implementation method 

 1. No gap

 2. standard


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.


how-to-add-sequence-in-odoo12-cybrosys




Comments

0


Leave a comment

 
Calicut

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

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

Kochi

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

Bangalore

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

Send Us A Message