Odoo Help


How can I create Employee Code in a sequence field

Debashis Das
on 6/18/13, 3:58 AM 12,536 views

I want to create Employee Code in a sequence field. Please suggest.

HI just go for various examples( like in sale ) module and look for sample reference field hope it will help

on 6/18/13, 5:38 AM


--Borni DHIFI--
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 


Skype : dhifi.borni

On 6/18/13, 5:45 AM


create a new sequence :

Settings>>Technical>> Sequences & Identifiers>>Sequence Codes. image description then

Settings>>Technical>> Sequences & Identifiers>>Sequences. image description

then create a new module to add a Employee Code

class hr_employee(osv.osv):
    _inherit = "hr.employee"

    def _get_code(self, cr, uid,context, *args):
        obj_sequence = self.pool.get('ir.sequence')    
        return obj_sequence.next_by_code(cr, uid, 'hr.employee.sequence', context=context)

    _columns = { 'code' : fields.char('Code', size=64), }

    _defaults = { 'code': _get_code, }


you can define this sequence in your module :

my_module_data.xml :

<?xml version="1.0" encoding="UTF-8"?>
    <data noupdate="0">
        <record model="ir.sequence.type" id="hr_employee_code_sequence">
            <field name="name">Code sequence hr employee</field>
            <field name="code">hr.employee.sequence</field>
        <record model="ir.sequence" id="hr_employee_sequence">
            <field name="name">Sequence For employee</field>
            <field name="code">hr.employee.sequence</field>
            <field name="active">TRUE</field>
            <field name="prefix">EMP</field>
            <field name="number_increment">1</field>
            <field name="number_next">1000</field>
            <field name="implementation">standard</field>

and in __openerp__.py:

"init_xml": ["my_module_data.xml"],

I have an error Constraint Error

code must be unique

Urpit Timbadiya
on 8/22/13, 12:45 PM

you can define a another sequence just replace <field name="code">hr.employee.sequence</field> to <field name="code">hr.employee.sequence2</field>

on 8/22/13, 7:05 PM

It works now.:) Thank you...

Urpit Timbadiya
on 8/23/13, 2:55 AM

Hi, i tried your answer but i'm getting following error {Validate Error The value "crm.helpesk.sequence2" for the field "ir_sequence.code" is not in the selection }

Sam path
on 3/27/14, 3:32 AM

@Borni This code is absolutely working. I want little different configuration. I have three companies-Software,Hardware,Factory. if employee 1 is in Software then employee id should be SOF001,...if employee 1 is in Hardware then employee id should be HAR001,...if employee 1 is in Factory then employee id should be FAC001,... how it generate automatically?

on 4/4/14, 9:30 AM

@Borni. Did you have any solution for my question?

on 4/4/14, 9:54 AM

@Borni, I have already wrote code this, but its not working. Can you please help me?

on 4/4/14, 10:25 AM
On 7/5/16, 5:01 AM

In odoo9 we can create a sequence code:

Create a new module name prod_quantity

 class prod_quantity(models.Model):     
  _name = 'products.car'

q_serial_no=fields.Char('Quantity Serial Number',default=lambda obj:



     <field name="q_serial_no"/>


 Create a new view file :


<data noupdate="0">

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

<field name="name">Sequence For Product</field>

<field name="code">products.car</field>

<field name="implementation">standard</field>

<field name="active">TRUE</field>

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

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

<field name="number_increment">1</field>

<field name="number_next_actual">1000</field>




Apply view file in openerp:

'data': [



It creates a sequence, but will advance the number even if you discard the new records, so it will skip numbers, how can that be fixed?

Alberto Lozano
on 6/11/17, 3:30 AM
Alberto Lozano
On 6/11/17, 3:29 AM

It creates a sequence, but will advance the number even if you discard the new records,  so it will skip numbers, how can that be fixed?

please someone delete this post, I added my comment here by mistake

Alberto Lozano
on 6/11/17, 3:32 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/18/13, 3:58 AM
Seen: 12536 times
Last updated: 6/11/17, 3:29 AM