2016-09-01 118 views
0

我需要聲明一個many2many字段作爲功能字段。我嘗試了下面的代碼,但沒有在數據庫中創建任何關係表。many2many odoo的功能字段8

def _get_function(self,cr,uid,ids,name,args,context=None): 
    resp={} 
    for data in self.browse(cr,uid,ids): 
     print'inside get Function' 
    return resp 

'many2many_ids': fields.function(_get_function, method=True, relation="table.table1", obj='table1_table2_rel', type="many2many" , string="Many2Many") 

現在數據保存在窗體視圖中,但我無法在另一個函數中訪問該值。 like,

for data in self.browse(cr,uid,ids): 
     print'many2many_ids',data.many2many_ids 

此處不顯示任何值。

我該怎麼做?

回答

0

如果你想存儲的字段使用「存儲」選項。

另外,您可能會考慮在v8上使用新的API。檢查官方文檔中的「計算字段」https://www.odoo.com/documentation/8.0/reference/orm.html

+0

當我使用store = True時出現錯誤:文件「/home/kabeer/git/liveAMS/openerp/models.py」,第2633行,在_auto_init中 cr.execute ('ALTER TABLE'%s「ADD COLUMN」%s「%s'%(self._table,k,get_pg_type(f)[1])) TypeError:'NoneType'對象沒有屬性'__getitem__' – KbiR