尝试在many2many字段中插入值时出现错误,您可以查看完整日志here
这是字段的声明
initial_project_ids = fields.Many2many(string="Initial project", comodel_name="project.project",
compute="_get_initial_project", relation="init", column1="in", column2="it",
store=True)
这是写方法的主要内容
@api.multi
def write(self, vals):
res = super(Project, self).write(vals)
if vals.get('upstream_project_ids') and self._context.get('update', True):
for upstream_project in self.upstream_project_ids:
upstream_project.with_context(update=False).update({'downstream_project_id': self.id})
# new implementation
# no risk of recursion
if self.project_type == "internal":
super(Project, self).write(
{'members_ids': [(6, 0, self.mapped("upstream_project_ids").mapped("members_ids").ids)],
'managers_ids': [(6, 0, self.mapped("upstream_project_ids").mapped("managers_ids").ids)],
'partners': [(6, 0, self.mapped("upstream_project_ids").mapped("partners").ids)]})
if self.project_type == 'valorization' and not self.check_protection:
super(Project, self).write(
{'managers_ids': [(6, 0, self.mapped("upstream_project_ids").mapped("managers_ids").ids)],
'partners': [(6, 0, self.mapped("upstream_project_ids").mapped("partners").ids)]})
if vals.get('downstream_project_id') and self._context.get('update', True):
self.downstream_project_id.with_contex(update=False).update({'upstream_project_ids': (4, self.id)})
return res
这是导致错误的方法
@api.depends("upstream_project_ids")
def _get_initial_project(self):
for record in self:
e = record.mapped("upstream_project_ids")
bak_e = False
while e:
bak_e = e
if record in e:
raise exceptions.Warning(
_(
'Recursion found')
)
e = e.mapped("upstream_project_ids")
if bak_e:
record.update(
{'initial_project_ids': [(6, 0, bak_e.ids)]})
我不知道这是怎么回事,这是什么问题,我尝试使用write方法,情感(=)但它不起作用。当我将initial_project_ids字段声明为many2one时,它起作用了。