2016-07-05 62 views
0

從昨天開始,我面臨着一個奇怪的problem.I'm嘗試所有的產品類別列表添加到在創建time.It接觸不工作既不是一個one2many/many2one relation或many2many/many2many relation。我最終會在聯繫人列表中列出一個空白的類別。錯誤,當試圖填補Many2many或One2many列表odoo V8

class product_category(models.Model): 
    _inherit = "product.category" 
    contacts = fields.Many2many('res.partner') 

class odepoContact(models.Model): 
    _inherit = "res.partner" 
    categs = fields.Many2many('product.category') 

    @api.model 
    def create(self, values): 
     ## Here categ is a list containing category ids. 
     categs = self.env['product.category'].search([]) 
     # values['categs'] = (4,0,categs) Not working =>EMPTY 
     # values['categs'] = categs Not working =>EMPTY 
     # values['categs'] = (6,0,categs) Not working =>EMPTY 
     id = super(odepoContact, self).create(values) 
     _logger.error(id.categs) 
     return id 
LOG:v8dev openerp.addons.org_chart_dept.org_chart: product.category() 

回答

1

你創建()應該是這樣的:

@api.model 
def create(self, values): 
    categs = self.env['product.category'].search([]) 
    values['categs'] = [(6,0,categs.ids)] 
    id = super(odepoContact, self).create(values) 
    _logger.error(id.categs) 
    return id 

該代碼示例是一個Many2Many場(categs),我寧願在這裏。對於Many2Many,你需要使用元組列表。你可以找到可能的元組here