Odoo Help

Welcome!

This community 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.

2

OpenERP get next Sequence number [Closed]

By
priyankahdp
on 3/25/13, 9:14 AM 5,132 views

The Question has been closed

by
priyankahdp
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.?

priyankahdp
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

priyankahdp
on 3/27/13, 10:41 AM
3

Yannick Vaucher

--Yannick Vaucher--
1699
| 5 7 9
Lausanne, Switzerland
--Yannick Vaucher--
Yannick Vaucher
On 3/25/13, 9:39 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 :-)

priyankahdp
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

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

Andre
on 5/2/15, 4:40 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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