Odoo Help


OpenERP get next Sequence number [Closed]

on 3/25/13, 9:14 AM 5,951 views

The Question has been closed

on 04/18/2013 07:32:59

OpenERP gives a sequence number when we saved a record. i have done that module.as per that module when i create a worker then load employee number as EMP001,EMP002..

My requirment is this. When I'm going to create a new employee then need to show next sequence number as a read only field. for ex : when i'm going to create a 9th employee then need to show EMP009 in my emp no field.

my current codes uploaded to below location https://github.com/priyankahdp/openerp/tree/openerp

Dear Yannik, here is the code.is it correct .?

def _get_next_no(self, cr, uid, context=None):
    cr.execute("SELECT last_value + increment_by FROM ir_sequence_%03d;" % seq['id'])
        seq['number_next'] = cr.fetchone()
    return seq

Your code is incomplete... You need to reconstruct the sequence number. And you also need to define the id of the sequence you are looking for. I only gave you the keys to open few doors. It's up to you to open those doors now.

Camptocamp SA
on 3/25/13, 1:49 PM

not clear it friend.. plz explain & show me watz the errors in my above function.?

on 3/25/13, 2:11 PM

This forum is not intended for python learning, you may need to open you python book this time :) Just a hint, what is seq['id'] ?

Camptocamp SA
on 3/27/13, 9:43 AM

thanks Yannik

on 3/27/13, 10:41 AM

There are no method to get this, you need to make your own by:

Getting your sequence id.

seq_id = self.pool.get('ir.sequence').search(cr, uid, [<search_cond>])

Then getting the next value based on last_value column from the postgresql sequence

"SELECT last_value + increment_by FROM ir_sequence_%03d;" %seq_id

Then from this number you need to reconstruct the sequence according to your format. With preffix and suffix.

Read the server/openerp/addons/base/ir/ir_sequence.py file you will see it in _next method

Remind that if two users are creating a record at the same time, they will see the same value but for one of them it will change on create action.

thank. please give me that above sql in function.awareness to handling "sql with cr.execute command" is very low of mine :-)

on 3/25/13, 9:46 AM

You might also try to directly uses the sequence.number_next attribute. In both case, you need to reconstruct your sequence number afterward.

Camptocamp SA
on 3/25/13, 9:53 AM

For sql it is somthing like that:

        cr.execute("SELECT last_value + increment_by FROM ir_sequence_%03d;" % seq['id'])
        seq['number_next'] = cr.fetchone()

However, using the number_next might be simpler and better.

Camptocamp SA
on 3/25/13, 9:56 AM

Dear Yannik, Please refer my edited post above & advice me

on 3/25/13, 1:19 PM

For everybody who is still searching. There is the next_by_code(sequence_code) method. I think that would do it for the new API. You can now do something like: next_seq = self.env['ir.sequence'].next_by_code('res.partner') Worked for me.

on 5/2/15, 4:40 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

0 follower(s)


Asked: 3/25/13, 9:14 AM
Seen: 5951 times
Last updated: 3/16/15, 8:10 AM