Odoo Help

Welcome!

This community 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.

0

SET The Identity (ID) SEED for new Entities

By
Paul Grimshaw
on 9/3/15, 11:02 AM 524 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--
10238
| 7 7 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--
896
| 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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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