Skip to Content
Menu
This question has been flagged
4887 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

Avatar
Discard
Related Posts Replies Views Activity
2
Feb 19
11981
3
Dec 23
6791
0
Mar 15
3937
1
Mar 15
7212
1
Mar 15
6229