Skip to Content
Menu
This question has been flagged
4 Replies
5926 Views

We have a lot of data synced to odoo from another system, direct to the database.  This is working fine in all manners.

However when we create a "New" entity, the ID that is given is far lower than a lot of the synced in data.

All we need to do is tell odoo to someone assign higher IDs to newly created entities.  Is there a way of doing this?

Avatar
Discard
Best Answer

You can do that by changing the related postgres sequence when you finish the sync

Avatar
Discard

This link may help to accomplish this task: https://wiki.postgresql.org/wiki/Fixing_Sequences

Author Best Answer

Not enough karma to comment, so thought I'd add it here.  Was simple to handle as Axel suggested, by altering the Postgres sequence.

    ALTER SEQUENCE res_partner_id_seq RESTART WITH 7000

The sequence name is constructed by:

[tablename]_[columnname]_seq
Thanks for the suggestions

Avatar
Discard

This seems nice and give the same result of my reply with less code, I upvoted your reply

Best Answer

I don't know if it is possible to tell Odoo to put the value of the ID higher than a specific value automatically.  But I have an idea, it is based on creating a loop that calls the create method several times to fill the gap between the last odoo ID and the new required ID and finally to raise an error to drop all issues for creation.

This is an idea and you have adjust it suitably on your system.

Here is the code.

I created the following class

class odoo_higher_sequence(osv.osv):
    _name = 'odoo.higher.sequence'
    _columns = {
        'field1':fields.integer('field1',),
   }
    def create(self,cr,uid,vals,context=None):
        new_id = super(odoo_higher_sequence,self).create(cr,uid,vals,context=context)
        o = self.browse(cr,uid,new_id)
        if o.field1 == 0:
            return new_id
        elif new_id  < o.field1:
            o.create(vals)
        else:
            raise osv.except_osv('Info!', 'IDs gap has been filled, you have to set the field1 to zero.')

 I put manually in field1 the desired new ID and click 'save', the create method is called recursively and new ids are created until the 'new_id' becomes greater than 'field1' value.

The user, or and automatic method, should at this point of time go and reset 'field1' to zero so that the 'create' method can do the save action.

I hope this idea be useful.

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 17
7221
0
Sep 15
3581
2
Sep 15
9435
1
Sep 15
4133
1
Sep 15
2528