Odoo Help

0

Problem initializing a field with a sequence

By
Pablo
on 3/13/13, 9:37 AM 1,138 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

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

0 follower(s)

Stats

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