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

Problem initializing a field with a sequence

By
Pablo
on 3/13/13, 9:37 AM 922 views

Hello

I have a problem with the initialization of a new field I have added to an existing model. I want this field to be unique and not null, but when I load my module those constraints can't be created due to the existing records in that table (the warning tells me to update the table contents and load the constraint manually). In order to avoid this, I'm trying to initialize the field using a sequence I load in a xml file (through "data" in __openerp__.py) with the following _defaults attribute

_defaults = {              
    'code_prefix' : lambda self,cr,uid,context=None: self.pool.get('ir.sequence').get(cr, uid, 'ags.test'),
}

But since the model is initialized before any data file is loaded, when the lambda function is executed in the initialization of the field for an existent record the sequence is not loaded yet.

Is there any way to bring forward the data load aside from creating an "initialization module" and adding a dependency to make it load before my module? How can I have the sequence available by the time the field is initialized?

Thanks in advance, Pablo

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

0 follower(s)

Stats

Asked: 3/13/13, 9:37 AM
Seen: 922 times
Last updated: 3/16/15, 8:10 AM