Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
7048 Zobrazení

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
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit

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

Autor Nejlepší odpověď

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
Zrušit

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

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 17
8371
0
zář 15
4519
2
zář 15
11118
1
zář 15
5227
1
zář 15
3683