對於我的用例,我試圖在創建時將所有產品類別列表添加到聯繫人。將列表添加到one2many
class product_category(models.Model):
_inherit = "product.category"
is_checked = fields.Boolean('Don', help="Check this box if this contact make Donation.")
resRelId = fields.Many2one('res.partner')
class res_partner(models.Model):
_inherit = "res.partner"
categs = fields.One2many('product.category','resRelId',String='Halo')
@api.model
def create(self, values):
categs = self.env['product.category'].search([])
new_id = super(res_partner, self).create(values)
for i in categs:
_logger.error(i)
new_id.write({'categs': i})
_logger.error(new_id.categs)
return new_id
我的代碼編譯沒有任何錯誤,但我一直在接觸一個空的產品列表結束了和我得到的警告。
2016-07-04 17:54:46,777 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(1,) == 1 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:800)
2016-07-04 17:54:46,777 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(1,) == 2 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:802)
2016-07-04 17:54:46,777 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(1,) == 3 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:804)
2016-07-04 17:54:46,777 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(1,) == 4 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:812)
2016-07-04 17:54:46,777 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(1,) == 5 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:818)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(1,) == 6 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:831)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(3,) == 1 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:800)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(3,) == 2 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:802)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(3,) == 3 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:804)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(3,) == 4 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:812)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(3,) == 5 (/home/odoo/odoo-dev/odoo/openerp/osv/fields.py:818)
2016-07-04 17:54:46,778 17751 WARNING v8dev openerp.models: Comparing apples and oranges: product.category(3,) == 6 (/home/odoo/odoo-
我有'TypeError:'int'對象沒有屬性'__getitem __''。而且,我認爲我不能使用(4,ID)。 從Odoo 8文檔: (4,id,_)將id id的現有記錄添加到集合中。 One2many無法使用。 –