跳至內容
選單
此問題已被標幟
5019 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
2月 19
12185
3
12月 23
6996
0
3月 15
4086
1
3月 15
7341
1
3月 15
6341