Odoo Help


Control on AutoGenerated Sequence Number [Closed]

on 6/25/13, 4:27 AM 5,933 views

The Question has been closed

on 09/27/2013 11:11:15

Hello All, In V7, How can I put control on generation of Automatic sequence numbers ? For example, If we take Manufacturing Order. When we create Manufacturing Order, a sequence like MO/0001 is generated. Suppose we discarded it without Saving. Next time when we create a new order the sequence we are getting is MO/0002. How to prevent this?

That is, a Sequence number should be incremented only if the previous one is saved.

Please help.



| 4 4 8
Ahmedabad, India

Odoo Expert

On 6/25/13, 4:53 AM


It is because sequence is called in _default of object. Like this,

_defaults = {
        'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'object.object'),

So whenever we create a new record _default will come into picture and directly add next sequence in record.

We can prevent this by overriding create() method. You can do like this,

def create(self, cr, uid, vals, context=None):
    if not vals:
        vals = {}
    if context is None:
        context = {}
    vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'object.object')
    return super(object, self).create(cr, uid, vals, context=context)

So sequence is added when you create a record and save it.


Dear Keyur,

In Each model I should override the Create method? Say for example, MRP..

* 'name': lambda x, y, z, c: x.pool.get('ir.sequence').get(y, z, 'mrp.production') or '/' *

It looke like this.

on 6/25/13, 5:28 AM

The problem is not for all the models. In some models sequence is called on a Done button, then you dont have to override create() method. So whenever the record is go to done state the sequence is called. My solution is for the scenario you specified in your question. For the specified scenario, yes you have to override create() method.

on 6/25/13, 6:32 AM



| 5 4 7
Baarn, Netherlands
On 6/25/13, 5:52 AM

For sale orders the described behavior is not what happens. With sale order, it will get a name/sequence number the moment you save the order (and make it a draft), or when you directly confirm the order.

It will be implicitly be saved when you click on update (to get the total at that moment).

When you start an order, and click on discard, there will be no new sequence number created.

So not all kind of orders behave like you say. Below is how sale_order is doing it. If you change it in your custom modules, it should be fine:

_defaults = {
    'name': lambda obj, cr, uid, context: '/',

def create(self, cr, uid, vals, context=None):
    if vals.get('name','/')=='/':
       vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'YOUR.MODEL') or '/'
    return super(YOUR_MODEL, self).create(cr, uid, vals, context=context)
brijesh savaliya
On 7/19/13, 7:33 AM

@ keyur can you please tell me where can i find the appropriate file for the changes done in that file

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: 6/25/13, 4:27 AM
Seen: 5933 times
Last updated: 3/3/17, 1:10 PM