我在复制 one2many 字段时遇到问题。我为项目创建分配字段:
assignment_ids = fields.One2many(
string='Project Assignments',
comodel_name='project.assignment',
inverse_name='project_id',
track_visibility='onchange',)
首先我尝试添加属性 copy=True 然后它抛出一个错误
验证约束时出错
预期单例:project.assignment(3, 4)
这有相同的单例错误
@api.multi
def copy(self, default=None):
default = default or {}
for rec in self:
list_assignment = self.assignment_ids
new_assignment = []
for assignment in list_assignment:
new_assignment.append((0, 0, {'id': assignment.id,
'role_id': assignment.role_id.id,
'date_join': date.today(),
'user_id': assignment.user_id.id,
}))
default['assignment_ids'] = new_assignment
return super(ProjectProject, self).copy(default)
然后我尝试覆盖复制功能。该分配有一个新项目的副本,但旧项目的分配已被删除。
@api.multi
def copy(self, default=None):
default = default or {}
list_assignment = self.assignment_ids
default['assignment_ids'] = (6, True, list_assignment)
return super(ProjectProject, self).copy(default)
那么如何复制这个 one2many 字段呢?
非常感谢!!!