Odoo Help


How to implement sequences [Closed]

on 3/29/13, 4:34 PM 14,342 views

The Question has been closed

Sudhir Arya (SA)
on 04/18/2013 05:20:12

I'm new at openerp and a little bit confused about all.

I would like to add a sequence to automatically create customers ID. For that I need to create a xml file and implement this, right?

But I have no idea where I have to do this. Is there a manual for openerp, where this is explained?

Thank you

Sudhir Arya (SA)
On 3/30/13, 10:42 AM

Create sequence.xml file and add it in data in __openerp__.py

Here is an example for sequence:

<record model="ir.sequence.type" id="seq_type_emp_id">
    <field name="name">Employee Number</field>
    <field name="code">hr.employee</field>
<record model="ir.sequence" id="seq_emp_id">
    <field name="name">Employee Number</field>
    <field name="code">hr.employee</field>
    <field name="prefix"></field>
    <field name="padding">3</field>

After creating sequence in xml, you can call that sequence from your code:

my_sequence = self.pool['ir.sequence'].get(cr, uid, seq_obj_name)
self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})

You can call this sequence either from create or from your own function or from _defaults.

Hope this will sort out your confusion.


Thanks for your answer, but this manual do not help me. I don't know where to call the sequence and also do not know the structure of a module. Isn't there sth. like an overview ? Thanks for your replies

on 3/30/13, 1:36 PM

Hi Sudhir, in self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})

what is [picking.id]? and also how can i use my current id without 'ids' in the argument field of the ORM create method

on 7/1/13, 3:57 AM

Add this in your create method:

vals['your_field_name'] = my_sequence
Sudhir Arya (SA)
on 7/1/13, 6:32 AM

yeah i tried... but this will provide the value after clicking on "SAVE" button.

on 7/1/13, 6:41 AM

That is normal. When you create a new record and click on Save button, create method is called and then record is saved to database.

Sudhir Arya (SA)
on 7/1/13, 6:54 AM

my requirement is to display the sequence generated in the form. If I use _defaults to provide the value... the sequence generated are always even numbers like E002, E004, E006, etc...

So how can I show the sequence at the same time the value must not change after clicking on "SAVE" button

on 7/1/13, 7:14 AM

If you are generating sequence code from _default, then make sure you have removed get sequence code from create method.

Sudhir Arya (SA)
on 7/1/13, 7:19 AM

If I use _default and display in the form, at the opening of the form the employee number is E001 and after adding values to other field. When "SAVE" button is clicked, the records employee number changes to E002.

on 7/1/13, 7:27 AM

Did you remove code from create method for sequence?

Sudhir Arya (SA)
on 7/1/13, 9:07 AM

I already removed it in create

on 7/1/13, 11:06 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

4 follower(s)


Asked: 3/29/13, 4:34 PM
Seen: 14342 times
Last updated: 3/24/17, 9:22 AM