对于我的用例,我试图在创建时将所有产品类别列表添加到联系人中。在
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
我的代码编译没有错误,但我总是在联系人中得到一个空的产品列表,我收到了这些警告。在
^{pr2}$
有一种最简单的方法。在
你正试图写入一个2many字段。你不是这样给一个20多岁的人写信的。在
以下是从one2many中添加和删除的各种方法的简便提示:
正确的方法是:
^{pr2}$相关问题 更多 >
编程相关推荐