Odoo Help

0

SET The Identity (ID) SEED for new Entities

By
Paul Grimshaw
on 9/3/15, 11:02 AM 783 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?

2

Axel Mendoza

--Axel Mendoza--
11956
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/3/15, 2:16 PM

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

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

Marvin Taboada
on 9/4/15, 2:52 AM
1
Paul Grimshaw
On 9/4/15, 5:27 AM

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

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

Tarek Mohamed Ibrahim
on 9/6/15, 5:03 AM
0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
904
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 9/4/15, 1:20 AM

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.

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.

Register

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

2 follower(s)

Stats

Asked: 9/3/15, 11:02 AM
Seen: 783 times
Last updated: 9/4/15, 5:29 AM