我为项目创建模块,当记录保存前缀生成时,序列为 pro-001
,其中包含字段前缀当在特定项目任务序列下创建任何任务时,将生成如 pro-001,pro-002,pro-003
def create(self, cr, uid, vals, context=None):
project_id = vals.get('project_id')
project = self.pool.get('project.project').read(cr, uid, project_id, context=context)
if project and project['prefix']:
new_id = self.pool.get('ir.sequence').next_by_id(cr, uid, 'project.task', project['prefix'], context=context)
return super(projectTask, self).create(cr, uid, vals, context)
答案 0 :(得分:0)
对于该要求,我建议为每个项目定义一个序列(sequence_id
见下文)。查看account.journal
它是如何正确完成的。
然后您可以在project.task
创建中使用它,例如:
def create(self, cr, uid, vals, context=None):
project_id = vals.get('project_id')
project = self.pool.get('project.project').browse(
cr, uid, project_id, context=context)
if project and project.sequence_id:
vals['your_sequence_field_on_task'] = self.pool.get('ir.sequence').next_by_id(
cr, uid, project.sequence_id.id, context=context)
return super(projectTask, self).create(cr, uid, vals, context)