在Odoo10中,使用UI我无法获得“服务器操作+自动操作”

2024-06-16 10:38:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我的任务中有可用的“审阅者”字段,当任务从“进行中”阶段移到“审阅”阶段时,我希望自动将审阅者与任务指派者切换。我的服务器操作中有以下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

不幸的是,将任务阶段更改为“审阅”并不能获得预期的结果。有什么建议吗?在

卡祖


Tags: torun代码nameinself服务器id
2条回答

好吧,我终于找到答案了。以下是Odoo 10上下文中的代码图片: enter image description here

不需要“for record”的“def”:代码将不运行。在

我只希望这对其他人有帮助。。。在

卡祖

我猜你是在错误地调用你想要得到的字段。在

# 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

此外,为什么不试着用^{} method代替呢?在

^{pr2}$

如果仍然有问题,可以使用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

相关问题 更多 >