在 odoo 10 中,使用 UI 我无法让我的 "Server action +Automated action" 工作

In odoo 10, using the UI I cannot get my "Server action +Automated action" to work

我的任务中有可用的 "reviewer" 字段,我想在任务从 'In progress' 阶段移动到 [=28= 阶段时自动切换审阅者与任务受让人] 阶段。我的服务器操作中有以下 Python 代码: picture of the code in context

def assignrev(self):
for record in self:
    if record['project.task.type.stage_id.name']=='Review':
        a=self.res.users.reviewer_id.name
        b=self.res.users.user_id.name
        record['res.users.user_id.name']=a
        record['res.users.reviewer_id.name']=b

以下是我的自动操作设置图片的链接: Server action to run

"When to run" settings

不幸的是,将任务阶段更改为 'Review' 并没有得到预期的结果。有什么建议吗?

和都

我的猜测是您错误地调用了您尝试获取的字段。

# Instead of this
a = self.res.users.reviewer_id.name
b = self.res.users.user_id.name
record['res.users.user_id.name']=a
record['res.users.reviewer_id.name']=b

# Try this
# You don't need to update the name, you need to update the database ID reference
record['user_id'] = record.reviewer_id.id
record['reviewer_id'] = record.user_id.id

此外,您为什么不尝试使用 onchange method 呢?

@api.multi
def onchange_state(self):
    for record in self:
        if record.stage_id.name == 'Review':
            record.update({
                'user_id': record.reviewer_id.id,
                'reviewer_id': record.user_id.id,
            })

如果您仍然遇到问题,您可以使用 ipdb 通过在您的方法中触发 set_trace 来更轻松地调试您的代码。

def assignrev(self):
    # Triggers a break in code so that you can debug
    import ipdb; ipdb.set_trace()
    for record in self:
        # Test line by line with the terminal to see where your problem is

好的,我终于找到了答案。下面是 Odoo 10 上下文中的代码图片:

不需要 "def" 个 "for record" 个:代码不会 运行。

我只希望这对其他人有所帮助...

和都