Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
OpenERP get next Sequence number [Closed]
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
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 :-)
You might also try to directly uses the sequence.number_next
attribute. In both case, you need to reconstruct your sequence number afterward.
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.
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.
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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 3/25/13, 9:14 AM |
Seen: 6764 times |
Last updated: 3/16/15, 8:10 AM |
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.
not clear it friend.. plz explain & show me watz the errors in my above function.?
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']
?thanks Yannik